diff options
author | Jean Delvare <jdelvare@suse.de> | 2012-02-01 18:08:49 +0100 |
---|---|---|
committer | Jean Delvare <jdelvare@suse.de> | 2012-02-01 18:08:49 +0100 |
commit | 430bb1c5ebd663d7cb797d29e2c90388c23c107c (patch) | |
tree | 80f8557691a9eca38830a07c99ce95b65cda3b08 | |
parent | 8a3f9645e0ea2709df4d4c68b352e46afe07919c (diff) | |
download | quilt-430bb1c5ebd663d7cb797d29e2c90388c23c107c.tar.gz |
backup-files: Quick exit when unlinking is not needed
The "check for hard links" use case is almost always a no-op. Check
if any work is needed at all first, and only if this is the case,
walk the list of files and unlink the faulty files. This approach
results in a huge performance gain in the most common case, and a
very small performance loss in the uncommon case.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Reviewed-by: Raphael Hertzog <hertzog@debian.org>
-rw-r--r-- | quilt/scripts/backup-files.in | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/quilt/scripts/backup-files.in b/quilt/scripts/backup-files.in index 5ee3c4f..8a8fb6c 100644 --- a/quilt/scripts/backup-files.in +++ b/quilt/scripts/backup-files.in @@ -187,6 +187,13 @@ noop_nolinks() fi } +# Test if some backed up files have a link count greater than 1 +some_files_have_links() +{ + (cd "$OPT_PREFIX" && find . -type f -print0) \ + | xargs -0 stat @STAT_HARDLINK@ 2> /dev/null | grep -qv '^1$' +} + ECHO=echo while [ $# -gt 0 ]; do @@ -256,6 +263,13 @@ if [ "$1" = - ]; then exit fi + # We typically expect the link count of backed up files to be 1 + # already, so check quickly that this is the case, and only if not, + # take the slow path and walk the file list in search of files to fix. + if [ "$OPT_WHAT" = noop_nolinks ] && ! some_files_have_links; then + exit + fi + find "$OPT_PREFIX" -type f -print \ | while read do |