aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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";
}
}
}