Make .etckeeper test that files actually exist before acting on them. Closes: #509888
authorJoey Hess <joey@gnu.kitenet.net>
Sat, 27 Dec 2008 19:31:47 +0000 (14:31 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Sat, 27 Dec 2008 19:31:47 +0000 (14:31 -0500)
debian/changelog
init.d/20restore-etckeeper
pre-commit.d/30store-metadata

index d287277b621cc1919883e63a344406537d15ab26..dd522bdeb0c5ff6250df02c01b729abe8b25be85 100644 (file)
@@ -1,3 +1,10 @@
+etckeeper (0.24) UNRELEASED; urgency=low
+
+  * Make .etckeeper test that files actually exist
+    before acting on them. Closes: #509888
+
+ -- Joey Hess <joeyh@debian.org>  Sat, 27 Dec 2008 14:27:43 -0500
+
 etckeeper (0.23) unstable; urgency=low
 
   * Fix hook scripts to use new etckeeper path. Closes: #509742
index 984d521c3ab8ab822d0b34232638474f1e411e94..69cbc3dac4f68faa120c8a1ab0f45e5353cce084 100755 (executable)
@@ -1,6 +1,17 @@
 #!/bin/sh
 set -e
 
+# Used by .etckeeper to run a command if the file it acts on
+# (the last parameter) exists.
+maybe () {
+       command="$1"
+       shift 1
+
+       if [ -e "$(eval echo \$$#)" ]; then
+               "$command" "$@"
+       fi
+}
+
 # Yes, this runs code from the repository. As documented, etckeeper-init
 # should only be run on repositories you trust.
 if [ -e .etckeeper ]; then
index 243e01991cda87db52f385c71b2e53fc191918f2..5d3496c7426999f8125733af706c0cdb3d5c922e 100755 (executable)
@@ -18,6 +18,9 @@ generate_metadata() {
        # This function generates the script commands to fix any files
        # that aren't owner=root, group=root, or mode=0644 or 0755.
        # The script is produced on stdout.  Errors go to stderr.
+       # 
+       # The script can use a 'maybe' function, which only runs a command
+       # if the file in its last argument exists.
 
        # We maintain the permissions on the directory containing VCS data
        # but we want find to ignore the VCS files themselves.
@@ -35,20 +38,20 @@ generate_metadata() {
        fi
 
        # Find all files and directories that don't have root as the owner
-       find $NOVCS \! -user root -exec stat --format="chown %U '{}'" {} \; \
-               | sort | filter_unknown chown owner
+       find $NOVCS \! -user root -exec stat --format="maybe chown %U '{}'" {} \; \
+               | sort | filter_unknown maybe chown owner
        # Find all files and directories that don't have root as the group
-       find $NOVCS \! -group root -exec stat --format="chgrp %G '{}'" {} \; \
-               | sort | filter_unknown chgrp group
+       find $NOVCS \! -group root -exec stat --format="maybe chgrp %G '{}'" {} \; \
+               | sort | filter_unknown maybe chgrp group
 
        # Find all directories that aren't 0755
        find $NOVCS -type d \! -perm 0755 \
-               -exec stat --format="chmod %a '{}'" {} \; | sort
+               -exec stat --format="maybe chmod %a '{}'" {} \; | sort
 
        # Find all files that aren't 0644 or 0755 (we can assume the VCS will
        # maintain the executable bit).
        find $NOVCS -type f \! -perm 0644 \! -perm 0755 \
-               -exec stat --format="chmod %a '{}'" {} \; | sort
+               -exec stat --format="maybe chmod %a '{}'" {} \; | sort
 
        # We don't handle xattrs.
        # Maybe check for getfattr/setfattr and use them if they're available?