use File::Compare;
use File::Temp;
-# Copyright (C) 2003-2006 Zygo Blaxell <zblaxell@feedme.hungrycats.org>
+# Copyright (C) 2003-2010 Zygo Blaxell <faster-dupemerge@mailtoo.hungrycats.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
my $printf_string = '%s ' .
($collapse_access ? '0 0 0 ' : '%U %G %m ') .
($collapse_timestamp ? '0 ' : '%T@ ') .
- '%D:%i %p\0';
+ '%D %i %p\0';
push(@find_command, '!', '-empty') unless $collapse_zero;
push(@find_command, '-printf', $printf_string);
}
}
+# Convert $dev,$ino into a single string where lexical and numeric orderings are equivalent
+sub format_inode ($$) {
+ my ($dev, $ino) = @_;
+ # 64 bits ought to be enough for everybody!
+ return sprintf('%016x:%016x', $dev, $ino);
+}
+
# Process all known files so far.
sub merge_files {
$merges_attempted++;
if ($ok) {
print STDERR "\t\tDigest is $digest\n" if $debug;
- my $incumbent = $hash_to_inode{$digest};
- if (defined($incumbent)) {
+ my $incumbent_list = ($hash_to_inode{$digest} ||= []);
+ my $incumbent_matched = 0;
+ for my $incumbent (sort @$incumbent_list) {
print STDERR "\t\tInodes $incumbent and $candidate have same hash\n" if $debug;
my $finished = 0;
until ($finished) {
my @incumbent_names = sort keys(%{$inode_to_file_name{$incumbent}});
my @candidate_names = sort keys(%{$inode_to_file_name{$candidate}});
- print STDERR "\t\tLinks to $incumbent:", join("\n\t\t\t", '', @incumbent_names), "\n" if $debug;
+ print STDERR "\t\tLinks to $incumbent:", join("\n\t\t\t", '', @incumbent_names), "\n" if $debug;
print STDERR "\t\tLinks to $candidate:", join("\n\t\t\t", '', @candidate_names), "\n" if $debug;
incumbent_file:
next incumbent_file;
}
- if ($incumbent_ino != $incumbent) {
- warn "$incumbent_file: expected inode $incumbent, found $incumbent_ino";
+ if (format_inode($incumbent_dev, $incumbent_ino) ne $incumbent) {
+ warn "$incumbent_file: expected inode $incumbent, found $incumbent_dev:$incumbent_ino";
$surprises++;
next incumbent_file;
}
next candidate_file;
}
- if ($candidate_ino != $candidate) {
- warn "$candidate_file: expected inode $candidate, found $candidate_ino";
+ if (format_inode($candidate_dev, $candidate_ino) ne $candidate) {
+ warn "$candidate_file: expected inode $candidate, found $candidate_dev:$candidate_ino";
$surprises++;
next candidate_file;
}
print STDERR "$quoted_incumbent_file and $quoted_candidate_file have same hash but do not compare equal!\n" unless $skip_hashes;
} else {
$identical = 1;
+ $incumbent_matched = 1;
}
$compare_count++;
$compare_bytes += $incumbent_size;
# My random number generator chooses the incumbent's size.
if ($link_done) {
- # Since we're in a dry run, the filesystem doesn't change.
- # Our notion of what the filesystem should look like should not change either.
delete $inode_to_file_name{$to_inode}->{$to_file};
- unless ($dry_run) {
- $inode_to_file_name{$from_inode}->{$to_file} = undef;
- $hash_to_inode{$digest} = $from_inode;
- }
+ $inode_to_file_name{$from_inode}->{$to_file} = undef;
+ $hash_to_inode{$digest} = [ $from_inode ];
$hard_links++;
if ($to_nlink == 1) {
}
$finished = 1;
}
- } else {
+ }
+ unless ($incumbent_matched) {
print STDERR "\t\tNew hash entered\n" if $debug;
- $hash_to_inode{$digest} = $candidate;
+ push(@$incumbent_list, $candidate);
}
} else {
warn "No digests found for inode $candidate\n";
}
while (<FIND>) {
- my ($weak_key, $inode, $name) = m/^(\d+ \d+ \d+ \d+ -?\d+) (\d+:\d+) (.+)\0$/so;
+ my ($weak_key, $dev, $ino, $name) = m/^(\d+ \d+ \d+ \d+ -?[\d.]+) (\d+) (\d+) (.+)\0$/so;
die "read error: $!\nLast input line was '$_'" unless defined($name);
+ my $inode = format_inode($dev, $ino);
+
print STDERR "weak_key=$weak_key inode=$inode name=$name\n" if $debug;
unless (! (-l $name) && (-f _)) {