]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
virfile: Check for existence of dir in virFileDeleteTree
authorJohn Ferlan <jferlan@redhat.com>
Tue, 15 Sep 2015 20:33:36 +0000 (16:33 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 16 Sep 2015 15:23:16 +0000 (11:23 -0400)
Commit id 'f1f68ca33' added code to remove the directory paths for
auto-generated sockets, but that code could be called before the
paths were created resulting in generating error messages from
virFileDeleteTree indicating that the file doesn't exist.

Rather than "enforce" all callers to make the non-NULL and existence
checks, modify the virFileDeleteTree API to silently ignore NULL on
input and non-existent directory trees.

src/qemu/qemu_process.c
src/util/virfile.c
tests/virhostdevtest.c
tests/virscsitest.c

index ce2c70cb3fd16990288262dfe71345fe56143ad1..155846e5dc40b0caf8150270573bda05d66e7060 100644 (file)
@@ -5269,14 +5269,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
 
     ignore_value(virAsprintf(&tmppath, "%s/domain-%s",
                              cfg->libDir, vm->def->name));
-    if (tmppath)
-        virFileDeleteTree(tmppath);
+    virFileDeleteTree(tmppath);
     VIR_FREE(tmppath);
 
     ignore_value(virAsprintf(&tmppath, "%s/domain-%s",
                              cfg->channelTargetDir, vm->def->name));
-    if (tmppath)
-        virFileDeleteTree(tmppath);
+    virFileDeleteTree(tmppath);
     VIR_FREE(tmppath);
 
     ignore_value(virDomainChrDefForeach(vm->def,
index 75819d9c8bd74a432397307834f7c0469fd058f5..fe9f8d4ce969cab4836adaf08e8089be57bf38b0 100644 (file)
@@ -934,13 +934,17 @@ int virFileNBDDeviceAssociate(const char *file,
  */
 int virFileDeleteTree(const char *dir)
 {
-    DIR *dh = opendir(dir);
+    DIR *dh;
     struct dirent *de;
     char *filepath = NULL;
     int ret = -1;
     int direrr;
 
-    if (!dh) {
+    /* Silently return 0 if passed NULL or directory doesn't exist */
+    if (!dir || !virFileExists(dir))
+        return 0;
+
+    if (!(dh = opendir(dir))) {
         virReportSystemError(errno, _("Cannot open dir '%s'"),
                              dir);
         return -1;
index 1e93819ce70400f60aa667725f57bde3b6e82922..065b825a5558b5b54031b33eaa9ac8748d454184 100644 (file)
@@ -65,7 +65,7 @@ myCleanup(void)
     }
 
     if (mgr) {
-        if (mgr->stateDir && !getenv("LIBVIRT_SKIP_CLEANUP"))
+        if (!getenv("LIBVIRT_SKIP_CLEANUP"))
             virFileDeleteTree(mgr->stateDir);
 
         virObjectUnref(mgr->activePCIHostdevs);
index a86ca28f4edec1f11c2f95a24480c06570fa94bd..88286f17b70211373819ff81347bbcc190139ce9 100644 (file)
@@ -241,7 +241,7 @@ mymain(void)
         ret = -1;
 
  cleanup:
-    if (tmpdir && getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
+    if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
         virFileDeleteTree(tmpdir);
     VIR_FREE(virscsi_prefix);
     return ret;