]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add virFileMakeParentPath helper function
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 30 Jan 2014 17:06:39 +0000 (17:06 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 18 Feb 2014 16:34:06 +0000 (16:34 +0000)
Add a helper function which takes a file path and ensures
that all directory components leading up to the file exist.
IOW, it strips the filename part of the path and passes
the result to virFileMakePath.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit c321bfc5c37c603af349dacf531bb03c91b0755e)

src/libvirt_private.syms
src/util/virfile.c
src/util/virfile.h

index 953b2e5c9f0196a9623d343b0aa9eca9b50dbd5e..0cdb41f7b8fadcd1e1759e5c3baee45c80710998 100644 (file)
@@ -1385,6 +1385,7 @@ virFileIsLink;
 virFileLinkPointsTo;
 virFileLock;
 virFileLoopDeviceAssociate;
+virFileMakeParentPath;
 virFileMakePath;
 virFileMakePathWithMode;
 virFileMatchesNameSuffix;
index 7eaabd06f4b30d108bbbd13b4a5bbe8e57756b33..589d2c425ebc9d01c32f11f245a95b2f0cfdac7d 100644 (file)
@@ -2178,6 +2178,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 *
index e2e708acca965fc36a5f39aa27f112141471f5ab..8cdfa86e13a4869c77298cf1700b088b553769b1 100644 (file)
@@ -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,