]> 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 18:25:46 +0000 (18:25 +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)

Conflicts:
src/libvirt_private.syms,
src/util/virfile.c,
src/util/virfile.h: Moved code to virutil.{c,h}

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

index a728fed3838479381bbbdd984dafe829ba2b906d..72367c6cc730120bf4c1d33c19bdf28c70b17b90 100644 (file)
@@ -1874,6 +1874,7 @@ virFileIsExecutable;
 virFileIsLink;
 virFileLinkPointsTo;
 virFileLock;
+virFileMakeParentPath;
 virFileMakePath;
 virFileMakePathWithMode;
 virFileMatchesNameSuffix;
index 1dcc5dfc1288d71e89866f0f0ff6f3645a1f6991..a728903413b92fa7631da7b519b713a04f3ac4a8 100644 (file)
@@ -1360,6 +1360,34 @@ cleanup:
     return ret;
 }
 
+int
+virFileMakeParentPath(const char *path)
+{
+    char *p;
+    char *tmp;
+    int ret = -1;
+
+    VIR_DEBUG("path=%s", path);
+
+    if (!(tmp = strdup(path))) {
+        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 750006ac49c04adada1c9172cb311c74b64d82a2..8f2d48118a972ad7b580555c207f31f5d06f2c3c 100644 (file)
@@ -123,6 +123,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,