summaryrefslogtreecommitdiff
path: root/pre-commit.d/30store-metadata
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2011-11-25 12:32:29 -0400
committerJoey Hess <joey@kitenet.net>2011-11-25 12:32:29 -0400
commit299dc44f1014404ca1367b72e2a22605ef22d127 (patch)
tree9b82b6779f5caa181308d43935faa5b3a8dd3ce8 /pre-commit.d/30store-metadata
parent77b86249c1787d700f3ef2016b0cbd3630d3b06a (diff)
Bugfix for filenames containing single quotes.
-- Joey Hess <joeyh@debian.org> Fri, 25 Nov 2011 12:00:55 -0400
Diffstat (limited to 'pre-commit.d/30store-metadata')
-rwxr-xr-xpre-commit.d/30store-metadata12
1 files changed, 9 insertions, 3 deletions
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