newer stuff forgot to commit

This commit is contained in:
Ward Wouts 2002-07-10 09:08:46 +00:00
parent 23e4c0e01b
commit bd9ce1578e

View file

@ -1,5 +1,8 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
# $Id$
# $Source$
# Generates a list of files in cur. dir which are actually the same # Generates a list of files in cur. dir which are actually the same
# Compares size and MD5 checksum # Compares size and MD5 checksum
# Handy for cleaning up pictures like this: # Handy for cleaning up pictures like this:
@ -7,6 +10,8 @@
# wishlist: # wishlist:
# - entering a list of file to check on the commandline # - entering a list of file to check on the commandline
# - include escapes in output (spaces, brackets, etc) (optional)
# - option to ignore 0 length files
# Changelog: # Changelog:
@ -18,7 +23,10 @@
# use MD5; instead of a shell call to md5 # use MD5; instead of a shell call to md5
# some cleaning of code # some cleaning of code
use MD5; use Digest::MD5;
use Getopt::Std;
getopts('s');
opendir(DIR, ".") or die "can't open . $!"; opendir(DIR, ".") or die "can't open . $!";
while (defined($file = readdir(DIR))) { while (defined($file = readdir(DIR))) {
@ -32,17 +40,24 @@ foreach (@filelist) {
} }
} }
foreach (keys %sizes) { foreach $size (keys %sizes) {
if (@{$sizes{$_}} > 1) { if (@{$sizes{$size}} > 1) {
%md5s = (); %md5s = ();
foreach (@{$sizes{$_}}) { foreach (@{$sizes{$size}}) {
push @{$md5s{&calc_md5($_)}}, $_; push @{$md5s{&calc_md5($_)}}, $_;
} }
foreach (keys %md5s) { foreach $key (keys %md5s) {
if (@{$md5s{$_}} > 1) { if ((@{$md5s{$key}} > 1) and !$opt_s ) {
foreach (@{$md5s{$_}}) { print "$_ "; } foreach (@{$md5s{$key}}) { print "$_ "; }
print "\n"; print "\n";
} }
elsif ((@{$md5s{$key}} > 1) and $opt_s ) {
@files = sort @{$md5s{$key}};
for $i (1 .. $#files) {
chomp $files[$i];
print "$files[$i]\n";
}
}
} }
} }
} }
@ -61,7 +76,7 @@ sub get_size {
sub calc_md5($file) { sub calc_md5($file) {
my ($file, $digest); my ($file, $digest);
$file = shift; $file = shift;
$md5 = new MD5; $md5 = Digest::MD5->new;
open FILE, "<$file" or die "couldn't open file: $!\n"; open FILE, "<$file" or die "couldn't open file: $!\n";
seek(FILE, 0, 0); seek(FILE, 0, 0);
$md5->reset; $md5->reset;