[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: mkinstalldirs: directory names with embedded whitespace or newlines
From: |
Alexandre Duret-Lutz |
Subject: |
Re: mkinstalldirs: directory names with embedded whitespace or newlines |
Date: |
Wed, 29 Jun 2005 23:04:25 +0200 |
User-agent: |
Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux) |
>>> "Stepan" == Stepan Kasal <address@hidden> writes:
[...]
Stepan> Are there any reasons why this shouldn't be commited?
I was waiting for feedback, and enough motivation to write a test case...
I'm installing this on HEAD and branch-1-9.
2005-06-29 Alexandre Duret-Lutz <address@hidden>
* lib/mkinstalldirs: Fix support for directory name with spaces if
`mkdir -p' does not work.
* tests/Makefile.am (TESTS): Add mkinst3.test.
* tests/mkinst3.test: New file.
Report from Noah Friedman.
Index: lib/mkinstalldirs
===================================================================
RCS file: /cvs/automake/automake/lib/mkinstalldirs,v
retrieving revision 1.18
diff -u -r1.18 mkinstalldirs
--- lib/mkinstalldirs 14 May 2005 20:28:50 -0000 1.18
+++ lib/mkinstalldirs 29 Jun 2005 21:02:10 -0000
@@ -1,7 +1,7 @@
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
-scriptversion=2005-05-14.22
+scriptversion=2005-06-29.22
# Original author: Noah Friedman <address@hidden>
# Created: 1993-05-16
@@ -12,7 +12,7 @@
# <address@hidden>.
errstatus=0
-dirmode=""
+dirmode=
usage="\
Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
@@ -103,13 +103,21 @@
for file
do
- set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
+ case $file in
+ /*) pathcomp=/ ;;
+ *) pathcomp= ;;
+ esac
+ oIFS=$IFS
+ IFS=/
+ set fnord $file
shift
+ IFS=$oIFS
- pathcomp=
for d
do
- pathcomp="$pathcomp$d"
+ test "x$d" = x && continue
+
+ pathcomp=$pathcomp$d
case $pathcomp in
-*) pathcomp=./$pathcomp ;;
esac
@@ -124,7 +132,7 @@
else
if test ! -z "$dirmode"; then
echo "chmod $dirmode $pathcomp"
- lasterr=""
+ lasterr=
chmod "$dirmode" "$pathcomp" || lasterr=$?
if test ! -z "$lasterr"; then
@@ -134,7 +142,7 @@
fi
fi
- pathcomp="$pathcomp/"
+ pathcomp=$pathcomp/
done
done
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.589
diff -u -r1.589 Makefile.am
--- tests/Makefile.am 23 Jun 2005 22:19:56 -0000 1.589
+++ tests/Makefile.am 29 Jun 2005 21:02:10 -0000
@@ -347,8 +347,9 @@
missing.test \
missing2.test \
missing3.test \
-mkinst2.test \
mkinstall.test \
+mkinst2.test \
+mkinst3.test \
mmodely.test \
multlib.test \
nobase.test \
Index: tests/mkinst3.test
===================================================================
RCS file: tests/mkinst3.test
diff -N tests/mkinst3.test
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/mkinst3.test 29 Jun 2005 21:02:10 -0000
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2005 Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Test mkinstalldirs with spaces in directory names.
+
+. ./defs || exit 1
+
+set -e
+
+# Make sure the directory we will create can be created...
+mkdir '~a b' || exit 77
+mkdir '~a b/-x y' || exit 77
+rm -rf '~a b'
+
+cp "$testsrcdir/../lib/mkinstalldirs" .
+
+# Test mkinstalldirs with the installed mkdir.
+
+./mkinstalldirs '~a b/-x y'
+test -d '~a b/-x y'
+rm -rf '~a b'
+
+# Trick mkinstalldirs into thinking mkdir does not support -p.
+
+cat >mkdir <<'EOF'
+#!/bin/sh
+case "$*" in
+ *-p*) exit 1;;
+esac
+PATH=$AM_PATH
+export PATH
+exec mkdir "$@"
+EOF
+
+chmod +x mkdir
+AM_PATH=$PATH
+export AM_PATH
+PATH=`pwd`:$PATH
+export PATH
+
+# Test mkinstalldirs without mkdir -p.
+
+./mkinstalldirs '~a b/-x y'
+test -d '~a b/-x y'
+rm -rf '~a b'
+
+./mkinstalldirs "`pwd`///~a b//-x y"
+test -d "`pwd`/~a b/-x y"
+rm -rf '~a b'
--
Alexandre Duret-Lutz