Package: etckeeper
Version: 0.23
Severity: normal
Tags: patch

There are cases when running `etckeeper init` fails while running
./.etckeeper because the referenced file (the one ./.etckeeper is trying
to chown|chgrp|chmod) doesn't exist. In that case, the chown|chgrp|chmod
cmd raises an error and etckeeper fails (because of set -e).

This could happen while running init on a cloned repository, if the file
is 'ignored' and doesn't have 'standard' ownership/permissions, or after
a checkout of a previous version, if the file is 'ignored', doesn't have
'standard' ownership/permissions and has been removed after the
just-checked-out commit.

IMHO, two workarounds exist:
1. make pre-commit.d/30store-metadata be aware of ignore-list when
generating .etckeeper
2. let .etckeeper test the existence of a file before trying to apply
stored metadata on it

The attached patch implements the latter one.

Thanks,
Gian Piero.

-- System Information:
Debian Release: 4.0
  APT prefers stable
  APT policy: (990, 'stable'), (500, 'testing')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/dash
Kernel: Linux 2.6.24-king2
Locale: LANG=it_IT.UTF8, LC_CTYPE=it_IT.UTF8 (charmap=UTF-8)
Sat Dec 27 14:04:54 CET 2008  "Gian Piero Carrubba" <[email protected]>
  * pre-commit.d/30store-metadata:
    - inside the generated .etckeeper, test if a file/dir exists before
      trying to apply the metadata
diff -rN -u old-etckeeper-0.23-new/pre-commit.d/30store-metadata 
new-etckeeper-0.23-new/pre-commit.d/30store-metadata
--- old-etckeeper-0.23-new/pre-commit.d/30store-metadata        2008-12-27 
14:13:17.000000000 +0100
+++ new-etckeeper-0.23-new/pre-commit.d/30store-metadata        2008-12-27 
14:13:17.000000000 +0100
@@ -14,6 +14,12 @@
        done
 }
 
+add_ifexists() {
+       while read cmd par file ; do
+               printf "%s\n" "test -e $file && $cmd $par $file"
+       done
+}
+
 generate_metadata() {
        # This function generates the script commands to fix any files
        # that aren't owner=root, group=root, or mode=0644 or 0755.
@@ -36,19 +42,19 @@
 
        # 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
+               | sort | filter_unknown chown owner | add_ifexists
        # 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
+               | sort | filter_unknown chgrp group | add_ifexists
 
        # Find all directories that aren't 0755
        find $NOVCS -type d \! -perm 0755 \
-               -exec stat --format="chmod %a '{}'" {} \; | sort
+               -exec stat --format="chmod %a '{}'" {} \; | sort | add_ifexists
 
        # 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="chmod %a '{}'" {} \; | sort | add_ifexists
 
        # We don't handle xattrs.
        # Maybe check for getfattr/setfattr and use them if they're available?

Reply via email to