diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-09-26 19:22:22 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-09-26 19:22:22 +1300 |
commit | 25997941931a8b843ab01e054492971ea1a019bc (patch) | |
tree | 42d4c03e937ced371656b4c418d408e6f1860fc3 /checkem | |
parent | Remove stray trailing comma (diff) | |
download | checkem-25997941931a8b843ab01e054492971ea1a019bc.tar.gz checkem-25997941931a8b843ab01e054492971ea1a019bc.zip |
Handle and print file errors properly
Diffstat (limited to 'checkem')
-rwxr-xr-x | checkem | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -20,6 +20,7 @@ use 5.006; # Import modules; Digest is the only one that wasn't in Perl 5.6 core use Carp; +use English '-no_match_vars'; use Fcntl ':mode'; use File::Find; use Digest; @@ -71,18 +72,26 @@ find { # Start a hash to represent this file my %f = ( name => $File::Find::name ); - # Pull in the file stat values we care about - @f{ keys %STATS } = ( stat $f{name} )[ values %STATS ] - or return; + # Pull in the stat values we care about + if ( @f{ keys %STATS } = ( stat $f{name} )[ values %STATS ] ) { - # Check it's a regular file - return if not $f{mode} & S_IFREG; + # Check it's a regular file + return if not $f{mode} & S_IFREG; - # Check its size is non-zero - return if not $f{size}; + # Check its size is non-zero + return if not $f{size}; - # Push the file hash into its size's bucket - return push @{ $sizes{ $f{size} } }, \%f; + # Push the file hash into its size's bucket + return push @{ $sizes{ $f{size} } }, \%f; + } + + # Complain that we couldn't stat + else { + carp "Could not stat $f{name}: $ERRNO"; + } + + # Return if we got to here + return; }, }, @ARGV; @@ -110,10 +119,10 @@ SIZE: for my $fs ( grep { @{$_} > 1 } values %sizes ) { $dig->addfile($fh); push @{ $sums{ $f->{hexdigest} = $dig->hexdigest() } }, $f; close $fh - or carp 'Failed to close file'; + or carp "Could not close $f->{name}: $ERRNO"; } else { - carp 'Failed to open file'; + carp "Could not open $f->{name}: $ERRNO"; } } } |