diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index e5fca898fb..15310cb74d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1380,6 +1380,7 @@ virFileIsLink; virFileLinkPointsTo; virFileLock; virFileLoopDeviceAssociate; +virFileMakeParentPath; virFileMakePath; virFileMakePathWithMode; virFileMatchesNameSuffix; diff --git a/src/util/virfile.c b/src/util/virfile.c index 6ed8db0c67..f913974fa3 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -2096,6 +2096,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 e2e708acca..8cdfa86e13 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -187,6 +187,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,