automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mkinstalldirs: directory names with embedded whitespace or newlines


From: Noah Friedman
Subject: mkinstalldirs: directory names with embedded whitespace or newlines
Date: Mon, 30 May 2005 19:20:56 -0700 (PDT)

I received a bug report about a KDE application that was using an old
version of mkinstalldirs and failed when one of the directories had an
embedded space in the name.  The following attachment is a diff against the
version in Automake 1.9 to handle this case.  (It's the "last resort" case
where mkdir -p doesn't work.)

--- /usr/share/automake-1.9/mkinstalldirs       2004-09-28 22:15:05.000000000 
-0700
+++ mkinstalldirs.new   2005-05-30 19:13:28.000000000 -0700
@@ -1,7 +1,7 @@
 #! /bin/sh
 # mkinstalldirs --- make directory hierarchy
 
-scriptversion=2004-02-15.20
+scriptversion=2005-05-30.19
 
 # Original author: Noah Friedman <address@hidden>
 # Created: 1993-05-16
@@ -101,41 +101,46 @@
     ;;
 esac
 
-for file
-do
-  set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
-  shift
 
-  pathcomp=
-  for d
-  do
-    pathcomp="$pathcomp$d"
-    case $pathcomp in
-      -*) pathcomp=./$pathcomp ;;
-    esac
-
-    if test ! -d "$pathcomp"; then
-      echo "mkdir $pathcomp"
-
-      mkdir "$pathcomp" || lasterr=$?
-
-      if test ! -d "$pathcomp"; then
-       errstatus=$lasterr
-      else
-       if test ! -z "$dirmode"; then
-         echo "chmod $dirmode $pathcomp"
-         lasterr=""
-         chmod "$dirmode" "$pathcomp" || lasterr=$?
+# newline
+nl='
+'
 
-         if test ! -z "$lasterr"; then
-           errstatus=$lasterr
-         fi
-       fi
-      fi
-    fi
-
-    pathcomp="$pathcomp/"
+for arg
+do
+  qdir=  dir=  qsub=  sub=//   # "//" can't appear normally
+  case $arg in
+    ./* | ../* | /* ) : ;;
+    * ) arg=./$arg ;;
+  esac
+  echo "$arg" \
+   | sed -n -e 's=///*=/=g;H;${g;s=#=:#:=g;s=/=###=g;:l' \
+            -e 's=^\(\n\)\(.*\)###=\1\2\1/\1=;t l' \
+            -e 's=:#:=#=g;s=^\n==p;}' \
+   | { read l; readstat=$?
+       while :; do
+         case $readstat:$l in
+           0:/ | [-1-9]*:* )
+             dir=$dir$sub  qdir=$qdir$qsub
+             if test -n "$dir" && ! test -d "$dir"; then
+               echo mkdir "$qdir"
+               mkdir "$dir"   || lasterr=$?
+               test -d "$dir" || { errstatus=$lasterr; break; }
+               if test -n "$dirmode" ; then
+                 echo "chmod $dirmode $qdir"
+                 chmod "$dirmode" "$dir" || errstatus=$?
+               fi
+             fi
+             test $readstat -ne 0 && break
+             qdir=$qdir/  dir=$dir/  qsub=  sub=// ;;
+           * ) case $sub in
+                 // ) sub=$l qsub=$l ;;
+                 *  ) sub=$sub$nl$l qsub=$qsub'\n'$l ;;
+               esac ;;
+         esac
+         read l; readstat=$?
   done
+     }
 done
 
 exit $errstatus

reply via email to

[Prev in Thread] Current Thread [Next in Thread]