mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virsh: Ensure the parents of the readline history path exists
Instead of changing the existed virFileMakePath to accept mode argument and modifying a pile of its uses, this patch introduces virFileMakePathWithMode, and use it instead of mkdir() to create the readline history dir.
This commit is contained in:
parent
fee00a6807
commit
ea9509b9e8
@ -1146,6 +1146,7 @@ virFileIsDir;
|
|||||||
virFileLinkPointsTo;
|
virFileLinkPointsTo;
|
||||||
virFileLock;
|
virFileLock;
|
||||||
virFileMakePath;
|
virFileMakePath;
|
||||||
|
virFileMakePathWithMode;
|
||||||
virFileMatchesNameSuffix;
|
virFileMatchesNameSuffix;
|
||||||
virFileOpenAs;
|
virFileOpenAs;
|
||||||
virFileOpenTty;
|
virFileOpenTty;
|
||||||
|
@ -1248,7 +1248,7 @@ int virDirCreate(const char *path ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
#endif /* WIN32 */
|
#endif /* WIN32 */
|
||||||
|
|
||||||
static int virFileMakePathHelper(char *path)
|
static int virFileMakePathHelper(char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *p;
|
char *p;
|
||||||
@ -1272,13 +1272,13 @@ static int virFileMakePathHelper(char *path)
|
|||||||
if (p != path) {
|
if (p != path) {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
if (virFileMakePathHelper(path) < 0)
|
if (virFileMakePathHelper(path, mode) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*p = '/';
|
*p = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mkdir(path, 0777) < 0 && errno != EEXIST)
|
if (mkdir(path, mode) < 0 && errno != EEXIST)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1291,6 +1291,13 @@ static int virFileMakePathHelper(char *path)
|
|||||||
* is set appropriately).
|
* is set appropriately).
|
||||||
*/
|
*/
|
||||||
int virFileMakePath(const char *path)
|
int virFileMakePath(const char *path)
|
||||||
|
{
|
||||||
|
return virFileMakePathWithMode(path, 0777);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
virFileMakePathWithMode(const char *path,
|
||||||
|
mode_t mode)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
@ -1298,7 +1305,7 @@ int virFileMakePath(const char *path)
|
|||||||
if ((tmp = strdup(path)) == NULL)
|
if ((tmp = strdup(path)) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = virFileMakePathHelper(tmp);
|
ret = virFileMakePathHelper(tmp, mode);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
|
@ -115,6 +115,8 @@ enum {
|
|||||||
int virDirCreate(const char *path, mode_t mode, uid_t uid, gid_t gid,
|
int virDirCreate(const char *path, mode_t mode, uid_t uid, gid_t gid,
|
||||||
unsigned int flags) ATTRIBUTE_RETURN_CHECK;
|
unsigned int flags) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virFileMakePath(const char *path) ATTRIBUTE_RETURN_CHECK;
|
int virFileMakePath(const char *path) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int virFileMakePathWithMode(const char *path,
|
||||||
|
mode_t mode) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
char *virFileBuildPath(const char *dir,
|
char *virFileBuildPath(const char *dir,
|
||||||
const char *name,
|
const char *name,
|
||||||
|
@ -20627,7 +20627,8 @@ static void
|
|||||||
vshReadlineDeinit (vshControl *ctl)
|
vshReadlineDeinit (vshControl *ctl)
|
||||||
{
|
{
|
||||||
if (ctl->historyfile != NULL) {
|
if (ctl->historyfile != NULL) {
|
||||||
if (mkdir(ctl->historydir, 0755) < 0 && errno != EEXIST) {
|
if (virFileMakePathWithMode(ctl->historydir, 0755) < 0 &&
|
||||||
|
errno != EEXIST) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
vshError(ctl, _("Failed to create '%s': %s"),
|
vshError(ctl, _("Failed to create '%s': %s"),
|
||||||
ctl->historydir, virStrerror(errno, ebuf, sizeof(ebuf)));
|
ctl->historydir, virStrerror(errno, ebuf, sizeof(ebuf)));
|
||||||
|
Loading…
Reference in New Issue
Block a user