[PATCH 1/4] virfile: Replace virFileMakePathHelper() with g_mkdir_with_parents()

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

 



Our virFileMakePathHelper() does exactly the same as
g_mkdir_with_parents() except for printing a debug message. Well,
tough luck. Replace the former with the latter.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/util/virfile.c | 47 ++--------------------------------------------
 1 file changed, 2 insertions(+), 45 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index 5710495bbf..dc6ba8e5c0 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -3037,45 +3037,6 @@ int virFileChownFiles(const char *name,
 }
 #endif /* WIN32 */
 
-static int
-virFileMakePathHelper(char *path, mode_t mode)
-{
-    struct stat st;
-    char *p;
-
-    VIR_DEBUG("path=%s mode=0%o", path, mode);
-
-    if (stat(path, &st) >= 0) {
-        if (S_ISDIR(st.st_mode))
-            return 0;
-
-        errno = ENOTDIR;
-        return -1;
-    }
-
-    if (errno != ENOENT)
-        return -1;
-
-    if ((p = strrchr(path, '/')) == NULL) {
-        errno = EINVAL;
-        return -1;
-    }
-
-    if (p != path) {
-        *p = '\0';
-
-        if (virFileMakePathHelper(path, mode) < 0)
-            return -1;
-
-        *p = '/';
-    }
-
-    if (g_mkdir(path, mode) < 0 && errno != EEXIST)
-        return -1;
-
-    return 0;
-}
-
 /**
  * Creates the given directory with mode 0777 if it's not already existing.
  *
@@ -3092,11 +3053,7 @@ int
 virFileMakePathWithMode(const char *path,
                         mode_t mode)
 {
-    g_autofree char *tmp = NULL;
-
-    tmp = g_strdup(path);
-
-    return virFileMakePathHelper(tmp, mode);
+    return g_mkdir_with_parents(path, mode);
 }
 
 
@@ -3116,7 +3073,7 @@ virFileMakeParentPath(const char *path)
     }
     *p = '\0';
 
-    return virFileMakePathHelper(tmp, 0777);
+    return g_mkdir_with_parents(tmp, 0777);
 }
 
 
-- 
2.26.2




[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]

  Powered by Linux