]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
storage: fs: Don't attempt directory creation if it already exists
authorCole Robinson <crobinso@redhat.com>
Mon, 27 Apr 2015 20:48:05 +0000 (16:48 -0400)
committerCole Robinson <crobinso@redhat.com>
Mon, 4 May 2015 16:56:38 +0000 (12:56 -0400)
The current code attempts to handle this, but it only catches mkdir
failing with EEXIST. However if say trying to build /tmp for an
unprivileged qemu:///session, mkdir will fail with EPERM.

Rather than catch any errors, just don't attempt mkdir if the directory
already exists.

src/util/virfile.c

index 87d121db5e8c05dd5e895587266efb304a04a206..984c5713c55205768362b669fd8c4f80cd90a9d5 100644 (file)
@@ -2289,12 +2289,13 @@ virDirCreateNoFork(const char *path,
     int ret = 0;
     struct stat st;
 
-    if ((mkdir(path, mode) < 0)
-        && !((errno == EEXIST) && (flags & VIR_DIR_CREATE_ALLOW_EXIST))) {
-        ret = -errno;
-        virReportSystemError(errno, _("failed to create directory '%s'"),
-                             path);
-        goto error;
+    if (!((flags & VIR_DIR_CREATE_ALLOW_EXIST) && !virFileExists(path))) {
+        if (mkdir(path, mode) < 0) {
+            ret = -errno;
+            virReportSystemError(errno, _("failed to create directory '%s'"),
+                                 path);
+            goto error;
+        }
     }
 
     if (stat(path, &st) == -1) {