From f8a17dc3c61e9daac88a105715e3584da6cec32a Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Fri, 8 Jan 2010 23:09:27 -0500 Subject: [PATCH] Allow --skip-hash and --skip-compare to be specified together Since --skip-hash is now a threshold parameter which applies to some files and not others, it makes sense to allow --skip-compare to be specified at the same time. --skip-compare is respected for files smaller than the --skip-hash threshold, since such files will always be hashed. --skip-compare is ignored for files larger than or equal to the --skip-hash threshold since such files will never be hashed. --- faster-dupemerge | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/faster-dupemerge b/faster-dupemerge index 14360dc..bc3a5af 100755 --- a/faster-dupemerge +++ b/faster-dupemerge @@ -86,6 +86,7 @@ my $collapse_access = 0; my $collapse_timestamp = 0; my $collapse_zero = 0; my $skip_compares = 0; +my $skip_compare_preference = 0; my $skip_hashes = 0; my $skip_hashes_threshold = 0; my $progress = 0; @@ -184,7 +185,7 @@ while ($#ARGV >= 0) { } elsif ($arg eq '--zeros') { $collapse_zero = 1; } elsif ($arg eq '--trust' || $arg eq '--skip-compare') { - $skip_compares = 1; + $skip_compare_preference = 1; } elsif ($arg =~ /^--skip-hash(?:=(\d+)([KkMmGgTt]?))?$/os) { my ($quantity, $unit) = ($1, $2); $unit ||= '_'; @@ -200,7 +201,8 @@ while ($#ARGV >= 0) { t => 1000*1000*1000*1000, T => 1024*1024*1024*1024, ); - $skip_hashes = $skip_hashes_threshold = $quantity * $scale{$unit}; + $skip_hashes = 0; + $skip_hashes_threshold = $quantity * $scale{$unit}; } elsif ($arg eq '--progress') { $progress = 1; } elsif ($arg eq '--verbose') { @@ -239,10 +241,6 @@ while ($#ARGV >= 0) { } } -if ($skip_hashes && $skip_compares) { - die "Cannot skip both hashes and compares.\n"; -} - @directories or usage; if (defined($lock_file) && !$dry_run) { @@ -597,7 +595,13 @@ while () { print STDERR "weak_key=$weak_key inode=$inode name=$name\n" if $debug; - $skip_hashes = $size >= $skip_hashes_threshold; + if ($size >= $skip_hashes_threshold) { + $skip_hashes = 1; + $skip_compares = 0; + } else { + $skip_hashes = 0; + $skip_compares = $skip_compare_preference; + } $input_links++; merge_files if $weak_key ne $current_key; -- 2.30.2