diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 67d20ed848..f22fe50ba8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1228,6 +1228,7 @@ virFileIsMountPoint; virFileLinkPointsTo; virFileLock; virFileLoopDeviceAssociate; +virFileMakeParentPath; virFileMakePath; virFileMakePathWithMode; virFileMatchesNameSuffix; diff --git a/src/util/virfile.c b/src/util/virfile.c index 631cd06b19..96f078dfd3 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -2340,6 +2340,35 @@ cleanup: return ret; } + +int +virFileMakeParentPath(const char *path) +{ + char *p; + char *tmp; + int ret = -1; + + VIR_DEBUG("path=%s", path); + + if (VIR_STRDUP(tmp, path) < 0) { + errno = ENOMEM; + return -1; + } + + if ((p = strrchr(tmp, '/')) == NULL) { + errno = EINVAL; + goto cleanup; + } + *p = '\0'; + + ret = virFileMakePathHelper(tmp, 0777); + + cleanup: + VIR_FREE(tmp); + return ret; +} + + /* Build up a fully qualified path for a config file to be * associated with a persistent guest or network */ char * diff --git a/src/util/virfile.h b/src/util/virfile.h index 0d20cdb7f9..20baf6f9d2 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -198,6 +198,7 @@ int virDirCreate(const char *path, mode_t mode, uid_t uid, gid_t gid, int virFileMakePath(const char *path) ATTRIBUTE_RETURN_CHECK; int virFileMakePathWithMode(const char *path, mode_t mode) ATTRIBUTE_RETURN_CHECK; +int virFileMakeParentPath(const char *path) ATTRIBUTE_RETURN_CHECK; char *virFileBuildPath(const char *dir, const char *name,