From 72fc4fc6977e1642df5246ea80b69dbcdd3206d4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 25 Nov 2011 12:52:23 -0400 Subject: 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. --- 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 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? -- cgit v1.2.3