]> xenbits.xensource.com Git - 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 12:39:06 +0000 (12:39 +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>
src/libvirt_private.syms
src/util/virfile.c
src/util/virfile.h

index 67d20ed848dae628ea5df488d1470dc16e049d45..f22fe50ba84e6fe45c14623fe6272d64e5c6518d 100644 (file)
@@ -1228,6 +1228,7 @@ virFileIsMountPoint;
 virFileLinkPointsTo;
 virFileLock;
 virFileLoopDeviceAssociate;
+virFileMakeParentPath;
 virFileMakePath;
 virFileMakePathWithMode;
 virFileMatchesNameSuffix;
index 631cd06b19fa169cf393904c8a176020b4bcf0f5..96f078dfd336e904e17c4c78b1b3079c3c383118 100644 (file)
@@ -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 *
index 0d20cdb7f92626af11d8732c085e02fab78cbb84..20baf6f9d2ec16d39f11816066bef4f7cc6ce417 100644 (file)
@@ -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,