diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2009-05-29 11:20:29 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2009-05-29 11:20:29 +0100 |
commit | f6e36bf361c587e0dbb2f0c71f5d22a7cf7f4f42 (patch) | |
tree | dc7a8538afe4fa534a68d47de6d7dcb3ba878098 /daemon | |
parent | 1e4173be10cf762c85f7f64ab27be98f3b57dd7a (diff) | |
download | libguestfs-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.c | 11 |
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. */ |