summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2009-05-29 11:20:29 +0100
committerRichard W.M. Jones <rjones@redhat.com>2009-05-29 11:20:29 +0100
commitf6e36bf361c587e0dbb2f0c71f5d22a7cf7f4f42 (patch)
treedc7a8538afe4fa534a68d47de6d7dcb3ba878098 /daemon
parent1e4173be10cf762c85f7f64ab27be98f3b57dd7a (diff)
downloadlibguestfs-f6e36bf361c587e0dbb2f0c71f5d22a7cf7f4f42.tar.gz
libguestfs-f6e36bf361c587e0dbb2f0c71f5d22a7cf7f4f42.tar.xz
libguestfs-f6e36bf361c587e0dbb2f0c71f5d22a7cf7f4f42.zip
Fix mkdir-p if directory exists (RHBZ#503133).
Diffstat (limited to 'daemon')
-rw-r--r--daemon/dir.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/daemon/dir.c b/daemon/dir.c
index f7064660..3df6233a 100644
--- a/daemon/dir.c
+++ b/daemon/dir.c
@@ -117,10 +117,21 @@ recursive_mkdir (const char *path)
int loop = 0;
int r;
char *ppath, *p;
+ struct stat buf;
again:
r = mkdir (path, 0777);
if (r == -1) {
+ if (errno == EEXIST) { /* Something exists here, might not be a dir. */
+ r = lstat (path, &buf);
+ if (r == -1) return -1;
+ if (!S_ISDIR (buf.st_mode)) {
+ errno = ENOTDIR;
+ return -1;
+ }
+ return 0; /* OK - directory exists here already. */
+ }
+
if (!loop && errno == ENOENT) {
loop = 1; /* Stops it looping forever. */