diff options
-rw-r--r-- | libbb/make_directory.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libbb/make_directory.c b/libbb/make_directory.c index 710537dd1..d07ccb93c 100644 --- a/libbb/make_directory.c +++ b/libbb/make_directory.c | |||
@@ -37,6 +37,7 @@ | |||
37 | 37 | ||
38 | #include <errno.h> | 38 | #include <errno.h> |
39 | #include <unistd.h> | 39 | #include <unistd.h> |
40 | #include <sys/stat.h> | ||
40 | #include "libbb.h" | 41 | #include "libbb.h" |
41 | 42 | ||
42 | int bb_make_directory (char *path, long mode, int flags) | 43 | int bb_make_directory (char *path, long mode, int flags) |
@@ -45,6 +46,7 @@ int bb_make_directory (char *path, long mode, int flags) | |||
45 | const char *fail_msg; | 46 | const char *fail_msg; |
46 | char *s = path; | 47 | char *s = path; |
47 | char c; | 48 | char c; |
49 | struct stat st; | ||
48 | 50 | ||
49 | mask = umask(0); | 51 | mask = umask(0); |
50 | umask(mask & ~0300); | 52 | umask(mask & ~0300); |
@@ -70,7 +72,9 @@ int bb_make_directory (char *path, long mode, int flags) | |||
70 | if (mkdir(path, 0777) < 0) { | 72 | if (mkdir(path, 0777) < 0) { |
71 | /* If we failed for any other reason than the directory | 73 | /* If we failed for any other reason than the directory |
72 | * already exists, output a diagnostic and return -1.*/ | 74 | * already exists, output a diagnostic and return -1.*/ |
73 | if (errno != EEXIST) { | 75 | if (errno != EEXIST |
76 | || !(flags & FILEUTILS_RECUR) | ||
77 | || (stat(path, &st) < 0 || !S_ISDIR(st.st_mode))) { | ||
74 | fail_msg = "create"; | 78 | fail_msg = "create"; |
75 | umask(mask); | 79 | umask(mask); |
76 | break; | 80 | break; |