From ee27d1a3d10f8f8e054fcc5f67d3ddcb7e304823 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 11 Aug 2017 19:29:27 +1200 Subject: Skip don't die on unreadable file --- checkem | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'checkem') diff --git a/checkem b/checkem index c9fdc32..343743f 100755 --- a/checkem +++ b/checkem @@ -25,7 +25,7 @@ use File::Find; use Digest; # Version number to make Perl::Critic happy -our $VERSION = 2.11; +our $VERSION = 2.12; # If no arguments, work with the current working directory if ( !@ARGV ) { @@ -91,13 +91,13 @@ find { # If there's more than one filename of any of the sizes, look for hard links, # checksum them if not linked, and push them into a sums table my %sums; -for my $fs ( grep { @{$_} > 1 } values %sizes ) { +SIZE: for my $fs ( grep { @{$_} > 1 } values %sizes ) { # Keep a temporary table of inodes to catch hard links my %inos; # Iterate through each file in the list - for my $f ( @{$fs} ) { + FILE: for my $f ( @{$fs} ) { # Catch hard links on compliant systems by keeping a dev/inode hash my ( $dev, $ino ) = @{$f}{qw(dev ino)}; @@ -108,19 +108,23 @@ for my $fs ( grep { @{$_} > 1 } values %sizes ) { # Files still the same size and not hard linked, group by digest; # create the digest object if it isn't already defined - open my $fh, '<', $f->{name} - or croak 'Failed to open file'; - binmode $fh; - $dig->addfile($fh); - push @{ $sums{ $dig->digest() } }, $f; - close $fh - or croak 'Failed to close file'; + if ( open my $fh, '<', $f->{name} ) { + binmode $fh; + $dig->addfile($fh); + push @{ $sums{ $dig->digest() } }, $f; + close $fh + or carp 'Failed to close file'; + } + else { + carp 'Failed to open file'; + } } } # Print the groups of matched files (more than one share a checksum in the # final table); sort the blocks by the filesize, and the files within each # block by name +GROUP: for my $group ( sort { $a->[0]{size} <=> $b->[0]{size} } grep { @{$_} > 1 } values %sums -- cgit v1.2.3