From 262b3c05dd946328c4264bbab48958161e36aa6b Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Mon, 27 Apr 2015 16:48:05 -0400 Subject: [PATCH] storage: fs: Don't attempt directory creation if it already exists 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 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 87d121db5e..984c5713c5 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -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) { -- GitLab