[PATCH 07/14] Add virFileMakeParentPath helper function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a helper function which takes a file path and ensures
that all directory components leading upto 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@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/util/virfile.c       | 27 +++++++++++++++++++++++++++
 src/util/virfile.h       |  1 +
 3 files changed, 29 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 2c9536a..5554a30 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1225,6 +1225,7 @@ virFileIsMountPoint;
 virFileLinkPointsTo;
 virFileLock;
 virFileLoopDeviceAssociate;
+virFileMakeParentPath;
 virFileMakePath;
 virFileMakePathWithMode;
 virFileMatchesNameSuffix;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 631cd06..92a8621 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -2340,6 +2340,33 @@ cleanup:
     return ret;
 }
 
+
+int
+virFileMakeParentPath(const char *path)
+{
+    char *p;
+    char *tmp;
+    int ret;
+
+    VIR_DEBUG("path=%s", path);
+
+    if (VIR_STRDUP(tmp, path) < 0) {
+        errno = ENOMEM;
+        return -1;
+    }
+
+    if ((p = strrchr(tmp, '/')) == NULL) {
+        errno = EINVAL;
+        return -1;
+    }
+    *p = '\0';
+
+    ret = virFileMakePathHelper(tmp, 0777);
+    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 0d20cdb..20baf6f 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,
-- 
1.8.5.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]