almost complete rewrite. much saner/faster now

This commit is contained in:
Ward Wouts 2001-08-30 09:51:04 +00:00
parent eb9135dded
commit ddbd3b5eb2

View file

@ -5,12 +5,15 @@
# Handy for cleaning up pictures like this: # Handy for cleaning up pictures like this:
# list_same|cut -f 1 -d " "|xargs rm # list_same|cut -f 1 -d " "|xargs rm
# This still sucks big time! # wishlist:
# Can it handle directories at all? # - entering a list of file to check on the commandline
# Why does it bother with calculating md5 checksums of everything,
# instead of just the files that have the same size?
# Changelog: # Changelog:
# 2001-08-30:
# _much_ saner now. only calculate md5s if sizes of
# files are the same
# nearly complete rewrite
# 2001-08-29: # 2001-08-29:
# 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
@ -19,42 +22,42 @@ use MD5;
opendir(DIR, ".") or die "can't open . $!"; opendir(DIR, ".") or die "can't open . $!";
while (defined($file = readdir(DIR))) { while (defined($file = readdir(DIR))) {
&get_finfo; push @filelist, $file;
} }
closedir(DIR); closedir(DIR);
$old_md5=""; foreach (@filelist) {
$old_size=""; if ( -f $_ ) {
$old_name=""; push @{$sizes{&get_size($_)}}, $_;
}
}
foreach $line (sort(@file_lijstje)) { foreach (keys %sizes) {
# print $line; if (@{$sizes{$_}} > 1) {
$line .= "\n"; %md5s = ();
$line =~ /(.*?)\s(.*?)\s(.*)/; foreach (@{$sizes{$_}}) {
$md5 = $1; $size = $2; $name = $3; push @{$md5s{&calc_md5($_)}}, $_;
if (($old_md5 eq $md5) && ($old_size eq $size)) { }
print "$old_name $name\n"; foreach (keys %md5s) {
} else { if (@{$md5s{$_}} > 1) {
$old_md5=$md5; foreach (@{$md5s{$_}}) { print "$_ "; }
$old_size=$size; print "\n";
$old_name=$name; }
}
} }
} }
################################# #################################
# dain bread functions # functions
sub get_finfo() { sub get_size {
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks); my $file = shift;
my $line; my @stat;
if (($file ne ".")&&($file ne "..")) { @stat = stat $file;
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, return $stat[7];
$atime,$mtime,$ctime,$blksize,$blocks) = stat $file;
$line = &calc_md5($file);
push @file_lijstje, "$line $size $file";
}
} }
# same md5 calculation i use in mv_wrap
sub calc_md5($file) { sub calc_md5($file) {
my ($file, $digest); my ($file, $digest);
$file = shift; $file = shift;