[PATCH 2/4] lib: Replace virFileMakePathWithMode() with g_mkdir_with_parents()

Michal Privoznik mprivozn at redhat.com
Mon Mar 1 09:36:14 UTC 2021


These functions are identical. Made using this spatch:

  @@
  expression path, mode;
  @@
  - virFileMakePathWithMode(path, mode)
  + g_mkdir_with_parents(path, mode)

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/interface/interface_backend_netcf.c | 2 +-
 src/interface/interface_backend_udev.c  | 2 +-
 src/node_device/node_device_udev.c      | 2 +-
 src/nwfilter/nwfilter_dhcpsnoop.c       | 2 +-
 src/nwfilter/nwfilter_driver.c          | 6 +++---
 src/qemu/qemu_namespace.c               | 2 +-
 src/qemu/qemu_process.c                 | 4 ++--
 src/qemu/qemu_tpm.c                     | 4 ++--
 src/rpc/virnetsocket.c                  | 2 +-
 src/secret/secret_driver.c              | 4 ++--
 src/util/virfile.c                      | 2 +-
 src/util/virlockspace.c                 | 2 +-
 src/util/virpidfile.c                   | 2 +-
 src/vz/vz_driver.c                      | 2 +-
 tests/scsihosttest.c                    | 4 ++--
 tools/vsh.c                             | 2 +-
 16 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c
index e40a4cb108..891271cb35 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -117,7 +117,7 @@ netcfStateInitialize(bool privileged,
         driver->stateDir = g_strdup_printf("%s/interface/run", rundir);
     }
 
-    if (virFileMakePathWithMode(driver->stateDir, S_IRWXU) < 0) {
+    if (g_mkdir_with_parents(driver->stateDir, S_IRWXU) < 0) {
         virReportSystemError(errno, _("cannot create state directory '%s'"),
                              driver->stateDir);
         goto error;
diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c
index 6a94a45044..e704400dc1 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -1147,7 +1147,7 @@ udevStateInitialize(bool privileged,
         driver->stateDir = g_strdup_printf("%s/interface/run", rundir);
     }
 
-    if (virFileMakePathWithMode(driver->stateDir, S_IRWXU) < 0) {
+    if (g_mkdir_with_parents(driver->stateDir, S_IRWXU) < 0) {
         virReportSystemError(errno, _("cannot create state directory '%s'"),
                              driver->stateDir);
         goto cleanup;
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 09048fb23f..fe25f8235e 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -2031,7 +2031,7 @@ nodeStateInitialize(bool privileged,
         driver->stateDir = g_strdup_printf("%s/nodedev/run", rundir);
     }
 
-    if (virFileMakePathWithMode(driver->stateDir, S_IRWXU) < 0) {
+    if (g_mkdir_with_parents(driver->stateDir, S_IRWXU) < 0) {
         virReportSystemError(errno, _("cannot create state directory '%s'"),
                              driver->stateDir);
         goto cleanup;
diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
index e64eb2c7ee..2e7190be1c 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -1811,7 +1811,7 @@ virNWFilterSnoopLeaseFileRefresh(void)
 {
     int tfd;
 
-    if (virFileMakePathWithMode(LEASEFILE_DIR, 0700) < 0) {
+    if (g_mkdir_with_parents(LEASEFILE_DIR, 0700) < 0) {
         virReportError(errno, _("mkdir(\"%s\")"), LEASEFILE_DIR);
         return;
     }
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 1b8e3dbad3..1541c44cf2 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -191,7 +191,7 @@ nwfilterStateInitialize(bool privileged,
 
     driver->stateDir = g_strdup(RUNSTATEDIR "/libvirt/nwfilter");
 
-    if (virFileMakePathWithMode(driver->stateDir, S_IRWXU) < 0) {
+    if (g_mkdir_with_parents(driver->stateDir, S_IRWXU) < 0) {
         virReportSystemError(errno, _("cannot create state directory '%s'"),
                              driver->stateDir);
         goto error;
@@ -224,7 +224,7 @@ nwfilterStateInitialize(bool privileged,
 
     driver->configDir = g_strdup(SYSCONFDIR "/libvirt/nwfilter");
 
-    if (virFileMakePathWithMode(driver->configDir, S_IRWXU) < 0) {
+    if (g_mkdir_with_parents(driver->configDir, S_IRWXU) < 0) {
         virReportSystemError(errno, _("cannot create config directory '%s'"),
                              driver->configDir);
         goto error;
@@ -232,7 +232,7 @@ nwfilterStateInitialize(bool privileged,
 
     driver->bindingDir = g_strdup(RUNSTATEDIR "/libvirt/nwfilter-binding");
 
-    if (virFileMakePathWithMode(driver->bindingDir, S_IRWXU) < 0) {
+    if (g_mkdir_with_parents(driver->bindingDir, S_IRWXU) < 0) {
         virReportSystemError(errno, _("cannot create config directory '%s'"),
                              driver->bindingDir);
         goto error;
diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c
index 60543e845b..f4b4d4d9ec 100644
--- a/src/qemu/qemu_namespace.c
+++ b/src/qemu/qemu_namespace.c
@@ -985,7 +985,7 @@ qemuNamespaceMknodOne(qemuNamespaceMknodItemPtr data)
             goto cleanup;
         }
         if ((isReg && virFileTouch(data->file, data->sb.st_mode) < 0) ||
-            (isDir && virFileMakePathWithMode(data->file, data->sb.st_mode) < 0))
+            (isDir && g_mkdir_with_parents(data->file, data->sb.st_mode) < 0))
             goto cleanup;
         delDevice = true;
         /* Just create the file here so that code below sets
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 398f63282e..944664ca28 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3937,7 +3937,7 @@ qemuProcessBuildDestroyMemoryPathsImpl(virQEMUDriverPtr driver,
         if (virFileExists(path))
             return 0;
 
-        if (virFileMakePathWithMode(path, 0700) < 0) {
+        if (g_mkdir_with_parents(path, 0700) < 0) {
             virReportSystemError(errno,
                                  _("Unable to create %s"),
                                  path);
@@ -5164,7 +5164,7 @@ qemuProcessMakeDir(virQEMUDriverPtr driver,
                    virDomainObjPtr vm,
                    const char *path)
 {
-    if (virFileMakePathWithMode(path, 0750) < 0) {
+    if (g_mkdir_with_parents(path, 0750) < 0) {
         virReportSystemError(errno, _("Cannot create directory '%s'"), path);
         return -1;
     }
diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index f94cad8230..2635382f81 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -95,7 +95,7 @@ qemuTPMEmulatorInitStorage(const char *swtpmStorageDir)
     int rc = 0;
 
     /* allow others to cd into this dir */
-    if (virFileMakePathWithMode(swtpmStorageDir, 0711) < 0) {
+    if (g_mkdir_with_parents(swtpmStorageDir, 0711) < 0) {
         virReportSystemError(errno,
                              _("Could not create TPM directory %s"),
                              swtpmStorageDir);
@@ -276,7 +276,7 @@ qemuTPMEmulatorPrepareHost(virDomainTPMDefPtr tpm,
         return -1;
 
     /* create log dir ... allow 'tss' user to cd into it */
-    if (virFileMakePathWithMode(logDir, 0711) < 0)
+    if (g_mkdir_with_parents(logDir, 0711) < 0)
         return -1;
 
     /* ... and adjust ownership */
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 17aaf86ce3..872b8a3c46 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -700,7 +700,7 @@ int virNetSocketNewConnectUNIX(const char *path,
         binname = g_path_get_basename(binary);
         rundir = virGetUserRuntimeDirectory();
 
-        if (virFileMakePathWithMode(rundir, 0700) < 0) {
+        if (g_mkdir_with_parents(rundir, 0700) < 0) {
             virReportSystemError(errno,
                                  _("Cannot create user runtime directory '%s'"),
                                  rundir);
diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index 45da09322b..c24aedbe1b 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -489,13 +489,13 @@ secretStateInitialize(bool privileged,
         driver->stateDir = g_strdup_printf("%s/secrets/run", rundir);
     }
 
-    if (virFileMakePathWithMode(driver->configDir, S_IRWXU) < 0) {
+    if (g_mkdir_with_parents(driver->configDir, S_IRWXU) < 0) {
         virReportSystemError(errno, _("cannot create config directory '%s'"),
                              driver->configDir);
         goto error;
     }
 
-    if (virFileMakePathWithMode(driver->stateDir, S_IRWXU) < 0) {
+    if (g_mkdir_with_parents(driver->stateDir, S_IRWXU) < 0) {
         virReportSystemError(errno, _("cannot create state directory '%s'"),
                              driver->stateDir);
         goto error;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index dc6ba8e5c0..bba0e892ea 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -3046,7 +3046,7 @@ int virFileChownFiles(const char *name,
 int
 virFileMakePath(const char *path)
 {
-    return virFileMakePathWithMode(path, 0777);
+    return g_mkdir_with_parents(path, 0777);
 }
 
 int
diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c
index 684a3320ed..f253091f39 100644
--- a/src/util/virlockspace.c
+++ b/src/util/virlockspace.c
@@ -263,7 +263,7 @@ virLockSpacePtr virLockSpaceNew(const char *directory)
                 goto error;
             }
         } else {
-            if (virFileMakePathWithMode(directory, 0700) < 0) {
+            if (g_mkdir_with_parents(directory, 0700) < 0) {
                 virReportSystemError(errno,
                                      _("Unable to create lockspace %s"),
                                      directory);
diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
index b4d0059405..4c38ebe500 100644
--- a/src/util/virpidfile.c
+++ b/src/util/virpidfile.c
@@ -489,7 +489,7 @@ virPidFileConstructPath(bool privileged,
     } else {
         rundir = virGetUserRuntimeDirectory();
 
-        if (virFileMakePathWithMode(rundir, 0700) < 0) {
+        if (g_mkdir_with_parents(rundir, 0700) < 0) {
             virReportSystemError(errno,
                                  _("Cannot create user runtime directory '%s'"),
                                  rundir);
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 0ebcb06234..a9f774afd6 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -4116,7 +4116,7 @@ vzStateInitialize(bool privileged,
 
     vz_driver_privileged = privileged;
 
-    if (virFileMakePathWithMode(VZ_STATEDIR, S_IRWXU) < 0) {
+    if (g_mkdir_with_parents(VZ_STATEDIR, S_IRWXU) < 0) {
         virReportSystemError(errno, _("cannot create state directory '%s'"),
                              VZ_STATEDIR);
         return VIR_DRV_STATE_INIT_ERROR;
diff --git a/tests/scsihosttest.c b/tests/scsihosttest.c
index 4b2779eabf..17825bba35 100644
--- a/tests/scsihosttest.c
+++ b/tests/scsihosttest.c
@@ -87,7 +87,7 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath,
     }
     spot--;
     *spot = '\0';
-    if (virFileMakePathWithMode(unique_id_path, 0755) < 0) {
+    if (g_mkdir_with_parents(unique_id_path, 0755) < 0) {
         fprintf(stderr, "Unable to make path to '%s'\n", unique_id_path);
         goto cleanup;
     }
@@ -102,7 +102,7 @@ create_scsihost(const char *fakesysfsdir, const char *devicepath,
     }
     spot--;
     *spot = '\0';
-    if (virFileMakePathWithMode(link_path, 0755) < 0) {
+    if (g_mkdir_with_parents(link_path, 0755) < 0) {
         fprintf(stderr, "Unable to make path to '%s'\n", link_path);
         goto cleanup;
     }
diff --git a/tools/vsh.c b/tools/vsh.c
index 68f04b2174..8fb033249e 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2870,7 +2870,7 @@ static void
 vshReadlineDeinit(vshControl *ctl)
 {
     if (ctl->historyfile != NULL) {
-        if (virFileMakePathWithMode(ctl->historydir, 0755) < 0 &&
+        if (g_mkdir_with_parents(ctl->historydir, 0755) < 0 &&
             errno != EEXIST) {
             vshError(ctl, _("Failed to create '%s': %s"),
                      ctl->historydir, g_strerror(errno));
-- 
2.26.2




More information about the libvir-list mailing list