From 299dc44f1014404ca1367b72e2a22605ef22d127 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 25 Nov 2011 12:32:29 -0400 Subject: Bugfix for filenames containing single quotes. -- Joey Hess Fri, 25 Nov 2011 12:00:55 -0400 --- pre-commit.d/30store-metadata | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'pre-commit.d/30store-metadata') diff --git a/pre-commit.d/30store-metadata b/pre-commit.d/30store-metadata index 2e35e6c..aeec374 100755 --- a/pre-commit.d/30store-metadata +++ b/pre-commit.d/30store-metadata @@ -32,10 +32,16 @@ filter_ignore() { statf() { while read statfile; do - echo "$(stat --format="$1" "$statfile") '$statfile'" + printf "$(stat --format="$1" "$statfile") " + echo "$statfile" | shellquote done } +shellquote() { + # Single quotes text, escaping existing single quotes. + sed -e "s/'/'\"'\"'/" -e "s/^/'/" -e "s/$/'/" +} + generate_metadata() { # This function generates the script commands to fix any files # that aren't owner=root, group=root, or mode=0644 or 0755. @@ -60,7 +66,7 @@ generate_metadata() { # These version control systems do not track directories, # so empty directories must be stored specially. find $NOVCS -type d -empty -print | - sort | sed -e "s/^/mkdir -p '/" -e "s/\$/'/" + sort | shellquote | sed -e "s/^/mkdir -p /" fi if [ "$VCS" = darcs ]; then @@ -68,7 +74,7 @@ generate_metadata() { # so they must be stored specially. find $NOVCS -type l -print | sort | filter_ignore | while read link; do dest=$( readlink "$link" ) - printf "ln -sf '%s' '%s'\n" "$dest" "$link" + printf "ln -sf '%s' '%s'\n" "$(echo "$dest" | shellquote)" "$(echo "$link" | shellquote)" done fi -- cgit v1.2.3