summaryrefslogtreecommitdiff
path: root/pre-commit.d/30store-metadata
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2011-11-25 12:52:23 -0400
committerJoey Hess <joey@kitenet.net>2011-11-25 12:52:23 -0400
commit72fc4fc6977e1642df5246ea80b69dbcdd3206d4 (patch)
tree9bc6e93ce8c006535a87014e8fb852acd883f1fe /pre-commit.d/30store-metadata
parent3137b75b6b0d86096e66daa24c477d4e71d85d77 (diff)
optimize file mode storing
Avoid runing stat(1) thousands of times. Note that etckeeper init is still slowed down by all this metadata, but that should be rarely used.
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 3b79e46..b2a8678 100755
--- a/pre-commit.d/30store-metadata
+++ b/pre-commit.d/30store-metadata
@@ -45,8 +45,7 @@ shellquote() {
generate_metadata() {
# This function generates the script commands to fix any file
# ownerships that aren't owner=root, group=root, as well as to
- # store the permissions of all files (all are needed because the
- # user may have an unusual umask).
+ # store the permissions of files.
# The script is produced on stdout. Errors go to stderr.
#
# The script can use a 'maybe' function, which only runs a command
@@ -85,7 +84,14 @@ generate_metadata() {
# Find all files and directories that don't have root as the group
find $NOVCS \! -group $(id -g) -print | statf "maybe chgrp %G" | sort | filter_unknown 'maybe chgrp' group
- find $NOVCS \( -type f -or -type d \) -print | statf "maybe chmod %a" | sort
+ # Store all file modes, in case the user has an unusual umask.
+ find $NOVCS \( -type f -or -type d \) -print | sort | perl -ne '
+ BEGIN { $q=chr(39) }
+ chomp;
+ my $mode = (stat($_))[2];
+ s/$q/$q"$q"$q/g; # escape single quotes
+ printf "maybe chmod %04o %s\n", $mode & 07777, "$q$_$q";
+ '
# We don't handle xattrs.
# Maybe check for getfattr/setfattr and use them if they're available?