Finish finddup

This doesn't look like it ever worked. Now it does.
This commit is contained in:
Peter J. Holzer 2019-04-20 00:59:42 +02:00
parent bcfae857e0
commit e4c489ce8f
1 changed files with 13 additions and 16 deletions

29
finddup Normal file → Executable file
View File

@ -6,7 +6,7 @@ finddup - yet another tool for finding duplicates
=cut =cut
use v5.10; use v5.20;
no autovivification 'fetch'; no autovivification 'fetch';
use File::Find; use File::Find;
use File::stat; use File::stat;
@ -25,17 +25,17 @@ find(sub {
unless ($files->{$size}{$hash}) { unless ($files->{$size}{$hash}) {
$files->{$size}{$hash} = []; $files->{$size}{$hash} = [];
} }
push $files->{$size}{$hash}, { path => $File::Find::name, push $files->{$size}{$hash}->@*, { path => $File::Find::name,
size => $size, size => $size,
dev => $st->dev, dev => $st->dev,
ino => $st->ino, ino => $st->ino,
}; };
} }
}, },
$filesdir $dir
); );
for my $size (keys $files) { for my $size (keys $files->%*) {
if (@{ $files->{$size}{""} } == 1) { if (@{ $files->{$size}{""} } == 1) {
next; next;
} }
@ -46,16 +46,14 @@ for my $size (keys $files) {
unless ($files->{$size}{$hash}) { unless ($files->{$size}{$hash}) {
$files->{$size}{$hash} = []; $files->{$size}{$hash} = [];
} }
push $files->{$size}{$hash}, $file; push $files->{$size}{$hash}->@*, $file;
} }
delete $files->{$size}{""}; delete $files->{$size}{""};
} }
for my $hash (keys $files->{$size}) { for my $hash (keys $files->{$size}->%*) {
if (@{ $files->{$size}{$hash} } > 1) { if (@{ $files->{$size}{$hash} } > 1) {
for my $file (@{ $files->{$size}{$hash} }) { while (my ($i, $file) = each @{ $files->{$size}{$hash} }) {
unless ($st->dev == $file->{dev} && $st->ino == $file->{ino}) { say "$i: $file->{path}";
say "$file->{path}";
}
} }
say ""; say "";
} }
@ -64,4 +62,3 @@ for my $size (keys $files) {
# vim: tw=132 sw=4 expandtab # vim: tw=132 sw=4 expandtab