changeset 1226:e1b09affb6db draft

Fix mkdir -p with absolute paths. Stripping leading / is not the right thing to do there. Broken when the code moved to lib and was genericized for use elsewhere.
author Rob Landley <rob@landley.net>
date Mon, 24 Mar 2014 06:26:49 -0500
parents 06206518a74c
children 903acf85bd1d
files lib/lib.c
diffstat 1 files changed, 3 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lib/lib.c	Wed Mar 19 13:57:06 2014 -0500
+++ b/lib/lib.c	Mon Mar 24 06:26:49 2014 -0500
@@ -135,15 +135,12 @@
     return 1;
   }
 
-  // Skip leading / of absolute paths
-  while (*dir == '/') dir++;
-
-  for (s=dir; ;s++) {
+  for (s = dir; ;s++) {
     char save = 0;
     mode_t mode = (0777&~toys.old_umask)|0300;
 
-    // Skip leading / of absolute paths.
-    if (*s == '/' && (flags&2)) {
+    // find next '/', but don't try to mkdir "" at start of absolute path
+    if (*s == '/' && (flags&2) && s != dir) {
       save = *s;
       *s = 0;
     } else if (*s) continue;