aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-06-29 19:57:09 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-06-29 19:57:09 +1200
commita54651d965bef436d5ad96cf9ead956db90c812f (patch)
tree86c5ef6fc5512340b054d5dbb29d9a0fdb05e512
parentee5262f15d673094ee13f8d30247bc96a54b34ae (diff)
parenta44548e805a382ec8b152aac35c8bb90fab1f3cb (diff)
downloadcheckem-master.tar.gz
checkem-master.zip
Merge branch 'release/v2.18'HEADv2.18master
* 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-xcheckem43
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
diff --git a/checkem b/checkem
index f2f031b..0cdc102 100755
--- a/checkem
+++ b/checkem
@@ -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";
}
}
}