Clean up script
This commit is contained in:
parent
801bed9fa9
commit
a10996e70f
|
@ -3,7 +3,7 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
our $VERSION = '1.2.2';
|
||||
our $VERSION = '1.2.3';
|
||||
|
||||
=pod
|
||||
|
||||
|
@ -115,7 +115,7 @@ Fixed bug when processing files with \r characters in the name.
|
|||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright (C) 2010-2013 Dan Church.
|
||||
Copyright (C) 2010-2018 Dan Church.
|
||||
|
||||
License GPLv3+: GNU GPL version 3 or later (L<http://gnu.org/licenses/gpl.html>).
|
||||
|
||||
|
@ -132,7 +132,6 @@ Written by Dan Church S<E<lt>amphetamachine@gmail.comE<gt>>
|
|||
use File::Find qw/ find /;
|
||||
require Digest::SHA;
|
||||
use Getopt::Std qw/ getopts /;
|
||||
require Pod::Text;
|
||||
|
||||
sub HELP_MESSAGE {
|
||||
# my $fh = shift;
|
||||
|
@ -152,6 +151,7 @@ sub HELP_MESSAGE {
|
|||
#symlinked by default.
|
||||
#EOF
|
||||
#;
|
||||
require Pod::Text;
|
||||
my ($fh, $pod) = (shift, Pod::Text->new);
|
||||
$pod->parse_from_file($0, $fh);
|
||||
|
||||
|
@ -202,8 +202,11 @@ sub findexec {
|
|||
return;
|
||||
}
|
||||
|
||||
# make sure the file exists and it's not a link
|
||||
if (-f $File::Find::name && ! -l $File::Find::name) {
|
||||
# skip non-existent files and links
|
||||
unless (-f $File::Find::name && ! -l $File::Find::name) {
|
||||
return;
|
||||
}
|
||||
|
||||
#my $ctx = Digest::MD5->new;
|
||||
my $ctx = Digest::SHA->new;
|
||||
$ctx->addfile($File::Find::name);
|
||||
|
@ -219,16 +222,16 @@ sub findexec {
|
|||
= ($File::Find::name, lstat $File::Find::name);
|
||||
|
||||
# skip zero-length files if wanted (`-z')
|
||||
# truth table:
|
||||
# -z | non-zero length | return?
|
||||
# 0 | 0 | 1
|
||||
# 0 | 1 | 0
|
||||
# 1 | 0 | 0
|
||||
# 1 | 1 | 0
|
||||
return unless $opts{z} or $entry->{size};
|
||||
|
||||
# check to see if we've come across a file with the same crc
|
||||
if (exists $files{$digest}) {
|
||||
# check to see if we've come across a file with the same checksum
|
||||
unless (exists $files{$digest}) {
|
||||
# the file is unique (as far as we know)
|
||||
# create a new entry in the hash table
|
||||
$files{$digest} = $entry;
|
||||
return;
|
||||
}
|
||||
|
||||
my $curr_entry = $files{$digest};
|
||||
|
||||
# don't waste my time
|
||||
|
@ -264,7 +267,6 @@ die "ERROR: checksums identical for two non-identical files!!!:\n".
|
|||
# must not already be hard-linked
|
||||
if ($curr_entry->{dev} == $entry->{dev} &&
|
||||
! $opts{s}) {
|
||||
# print "hard-linking $new_file\t=>$old_file\n";
|
||||
# attempt to unlink the file
|
||||
printf STDERR "removing file `%s'\n",
|
||||
$less_linked->{name} if $opts{v};
|
||||
|
@ -272,11 +274,7 @@ die "ERROR: checksums identical for two non-identical files!!!:\n".
|
|||
|
||||
# couldn't do it; try more-linked file
|
||||
|
||||
printf STDERR <<EOF
|
||||
Failed to remove file `%s': %s
|
||||
(using `%s')
|
||||
EOF
|
||||
,
|
||||
printf STDERR "Failed to remove file `%s': %s\n(using `%s')\n",
|
||||
$less_linked->{name},
|
||||
$!,
|
||||
$more_linked->{name}
|
||||
|
@ -285,11 +283,7 @@ EOF
|
|||
# if we can't do this, there's no point
|
||||
# in continuing
|
||||
unless (unlink $more_linked->{name}) {
|
||||
printf STDERR <<EOF
|
||||
Failed to remove file `%s' (second failure on match): %s
|
||||
Skipping...
|
||||
EOF
|
||||
,
|
||||
printf STDERR "Failed to remove file `%s' (second failure on match): %s\nSkipping...\n",
|
||||
$more_linked->{name},
|
||||
$!
|
||||
if $opts{v};
|
||||
|
@ -358,11 +352,6 @@ EOF
|
|||
# preserve older time stamp
|
||||
utime $atime, $mtime, $less_linked->{name};
|
||||
}
|
||||
} else {
|
||||
# the file is unique (as far as we know)
|
||||
# create a new entry in the hash table
|
||||
$files{$digest} = $entry;
|
||||
}
|
||||
#} elsif (-l $File::Find::name) {
|
||||
# # do something to simplify symlinks
|
||||
# printf STDERR "FIXME: simplifying symlink `%s'\n",
|
||||
|
@ -372,7 +361,6 @@ EOF
|
|||
# printf STDERR "symlink `%s' points to `%s'\n",
|
||||
# $File::Find::name, readlink $File::Find::name;
|
||||
}
|
||||
}
|
||||
|
||||
printf STDERR "freed %d bytes (%0.4G %s)\n",
|
||||
$freed_bytes, &hr_size($freed_bytes)
|
||||
|
|
Loading…
Reference in New Issue