diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-06-29 19:57:09 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-06-29 19:57:09 +1200 |
commit | a54651d965bef436d5ad96cf9ead956db90c812f (patch) | |
tree | 86c5ef6fc5512340b054d5dbb29d9a0fdb05e512 | |
parent | Detect plain file and not symlink correctly (diff) | |
parent | Bump VERSION (diff) | |
download | checkem-master.tar.gz checkem-master.zip |
* release/v2.18:
Bump VERSION
Refactor digest alg selection
Use interpolated error string
Order modules alphabetically
Use `main` package
Rename README to .md
Remove Carp dependency
-rw-r--r-- | README.md (renamed from README.markdown) | 0 | ||||
-rwxr-xr-x | checkem | 43 |
2 files changed, 18 insertions, 25 deletions
diff --git a/README.markdown b/README.md index d09bc87..d09bc87 100644 --- a/README.markdown +++ b/README.md @@ -6,9 +6,7 @@ # Author: Tom Ryder <tom@sanctum.geek.nz> # Site: <https://sanctum.geek.nz/cgit/checkem.git> # - -# Package name -package File::Duplicates::Checkem; +package main; # Force me to write this properly use strict; @@ -19,18 +17,17 @@ use utf8; use 5.006; # Import modules; Digest is the only one that wasn't in Perl 5.6 core -use Carp; +use Digest; use English '-no_match_vars'; use Fcntl ':mode'; use File::Find; -use Digest; # Version number to make Perl::Critic happy -our $VERSION = 2.17; +our $VERSION = 2.18; # Complain if there are no arguments if ( !@ARGV ) { - printf {*STDERR} "%s\n", 'Need at least one file or directory'; + printf {*STDERR} "Need at least one file or directory\n"; exit 2; } @@ -43,23 +40,19 @@ my %STATS = ( size => 7, ); -# We need to pick and create a Digest object -my $dig; +# Use either the specified algorithm or a default list +my @algs = + exists $ENV{CHECKEM_ALG} + ? $ENV{CHECKEM_ALG} + : qw(SHA-256 SHA-1 MD5); -# We were told which algorithm to use -if ( exists $ENV{CHECKEM_ALG} ) { - $dig = Digest->new( $ENV{CHECKEM_ALG} ); -} - -# Try worse and worse algorithms until we get a digest object -else { - for my $alg (qw(SHA-256 SHA-1 MD5)) { - last if eval { $dig = Digest->new($alg) }; - } +# Build digest object or give up +my $dig; +for (@algs) { + last if eval { $dig = Digest->new($_) }; } - -# Still no digest object, give up -defined $dig or croak 'Could not create a useable Digest object'; +defined $dig + or die "Could not create a useable Digest object\n"; # Start a hash of filesizes to file names/stats... my %sizes; @@ -87,7 +80,7 @@ find { # Complain that we couldn't stat else { - carp "Could not stat $f{name}: $ERRNO"; + warn "Could not stat $f{name}: $ERRNO\n"; } # Return if we got to here @@ -119,10 +112,10 @@ SIZE: for my $fs ( grep { @{$_} > 1 } values %sizes ) { $dig->addfile($fh); push @{ $sums{ $f->{hexdigest} = $dig->hexdigest() } }, $f; close $fh - or carp "Could not close $f->{name}: $ERRNO"; + or warn "Could not close $f->{name}: $ERRNO\n"; } else { - carp "Could not open $f->{name}: $ERRNO"; + warn "Could not open $f->{name}: $ERRNO\n"; } } } |