summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-08-15 19:18:35 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-08-15 19:18:35 +0000
commit11152e30e3d8091a76adf2bfe59754d93becf724 (patch)
treeeb3d3a084b931938aed97b3b51ce640232707e36
parentcd785fb716769228082ab1fd690d7916e3cc9cee (diff)
downloadbusybox-w32-11152e30e3d8091a76adf2bfe59754d93becf724.tar.gz
busybox-w32-11152e30e3d8091a76adf2bfe59754d93becf724.tar.bz2
busybox-w32-11152e30e3d8091a76adf2bfe59754d93becf724.zip
mkdir: fix "uname 0222; mkdir foo/bar" case
(by Doug Graham <dgraham AT nortel.com>) function old new delta bb_make_directory 291 280 -11
-rw-r--r--libbb/make_directory.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/libbb/make_directory.c b/libbb/make_directory.c
index 5c71aff92..df0b4a13d 100644
--- a/libbb/make_directory.c
+++ b/libbb/make_directory.c
@@ -35,17 +35,10 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags)
35 struct stat st; 35 struct stat st;
36 36
37 mask = umask(0); 37 mask = umask(0);
38 if (mode == -1) { 38 umask(mask & ~0300); /* Ensure intermediate dirs are wx */
39 umask(mask);
40 mode = (S_IXUSR | S_IXGRP | S_IXOTH |
41 S_IWUSR | S_IWGRP | S_IWOTH |
42 S_IRUSR | S_IRGRP | S_IROTH) & ~mask;
43 } else {
44 umask(mask & ~0300);
45 }
46 39
47 do { 40 while (1) {
48 c = 0; 41 c = '\0';
49 42
50 if (flags & FILEUTILS_RECUR) { /* Get the parent. */ 43 if (flags & FILEUTILS_RECUR) { /* Get the parent. */
51 /* Bypass leading non-'/'s and then subsequent '/'s. */ 44 /* Bypass leading non-'/'s and then subsequent '/'s. */
@@ -54,20 +47,24 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags)
54 do { 47 do {
55 ++s; 48 ++s;
56 } while (*s == '/'); 49 } while (*s == '/');
57 c = *s; /* Save the current char */ 50 c = *s; /* Save the current char */
58 *s = 0; /* and replace it with nul. */ 51 *s = '\0'; /* and replace it with nul. */
59 break; 52 break;
60 } 53 }
61 ++s; 54 ++s;
62 } 55 }
63 } 56 }
64 57
58 if (!c) /* Last component uses orig umask */
59 umask(mask);
60
65 if (mkdir(path, 0777) < 0) { 61 if (mkdir(path, 0777) < 0) {
66 /* If we failed for any other reason than the directory 62 /* If we failed for any other reason than the directory
67 * already exists, output a diagnostic and return -1.*/ 63 * already exists, output a diagnostic and return -1. */
68 if (errno != EEXIST 64 if (errno != EEXIST
69 || !(flags & FILEUTILS_RECUR) 65 || !(flags & FILEUTILS_RECUR)
70 || (stat(path, &st) < 0 || !S_ISDIR(st.st_mode))) { 66 || ((stat(path, &st) < 0) || !S_ISDIR(st.st_mode))
67 ) {
71 fail_msg = "create"; 68 fail_msg = "create";
72 umask(mask); 69 umask(mask);
73 break; 70 break;
@@ -82,11 +79,10 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags)
82 } 79 }
83 80
84 if (!c) { 81 if (!c) {
85 /* Done. If necessary, updated perms on the newly 82 /* Done. If necessary, update perms on the newly
86 * created directory. Failure to update here _is_ 83 * created directory. Failure to update here _is_
87 * an error.*/ 84 * an error. */
88 umask(mask); 85 if ((mode != -1) && (chmod(path, mode) < 0)) {
89 if ((mode != -1) && (chmod(path, mode) < 0)){
90 fail_msg = "set permissions of"; 86 fail_msg = "set permissions of";
91 break; 87 break;
92 } 88 }
@@ -95,8 +91,7 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags)
95 91
96 /* Remove any inserted nul from the path (recursive mode). */ 92 /* Remove any inserted nul from the path (recursive mode). */
97 *s = c; 93 *s = c;
98 94 } /* while (1) */
99 } while (1);
100 95
101 bb_perror_msg("cannot %s directory '%s'", fail_msg, path); 96 bb_perror_msg("cannot %s directory '%s'", fail_msg, path);
102 return -1; 97 return -1;