mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
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.
This commit is contained in:
parent
d6f8b35db5
commit
262b3c05dd
@ -2289,12 +2289,13 @@ virDirCreateNoFork(const char *path,
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if ((mkdir(path, mode) < 0)
|
if (!((flags & VIR_DIR_CREATE_ALLOW_EXIST) && !virFileExists(path))) {
|
||||||
&& !((errno == EEXIST) && (flags & VIR_DIR_CREATE_ALLOW_EXIST))) {
|
if (mkdir(path, mode) < 0) {
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
virReportSystemError(errno, _("failed to create directory '%s'"),
|
virReportSystemError(errno, _("failed to create directory '%s'"),
|
||||||
path);
|
path);
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(path, &st) == -1) {
|
if (stat(path, &st) == -1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user