aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-08-10 01:07:17 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-08-10 01:17:24 +1200
commitab97942d06a3946cff48f4027740a31ceae1ad8a (patch)
tree3ca2c377b8c7b99cca316f2cac5b658519f34ca5
parentUse correct format for version string (diff)
downloadcheckem-ab97942d06a3946cff48f4027740a31ceae1ad8a.tar.gz (sig)
checkem-ab97942d06a3946cff48f4027740a31ceae1ad8a.zip
Use generic Digest module frontendv2.8
Slightly older in core, enables using MD5 if need be
-rwxr-xr-xcheckem33
1 files changed, 19 insertions, 14 deletions
diff --git a/checkem b/checkem
index 0035cee..96d6508 100755
--- a/checkem
+++ b/checkem
@@ -1,8 +1,10 @@
#!/usr/bin/env perl
#
-# checkem: Find groups of duplicate files with libraries that have been in Perl
-# Core since version 5.9.3
+# checkem: Find groups of duplicate files with core libraries.
+#
+# Author: Tom Ryder <tom@sanctum.geek.nz>
+# Site: <https://sanctum.geek.nz/cgit/checkem.git>
#
# Package name
@@ -13,18 +15,17 @@ use strict;
use warnings;
use utf8;
-# Get the find and current working directory modules
+# Tolerate very old Perls
+use 5.006;
+
+# Import required modules
use Carp;
use Fcntl ':mode';
use File::Find;
-use Digest::SHA;
-
-# Lowest version number that has all of those core modules; Digest::SHA is the
-# newest
-use 5.009_003;
+use Digest;
# Version number to make Perl::Critic happy
-our $VERSION = 2.7;
+our $VERSION = 2.8;
# If no arguments, work with the current working directory
if ( !@ARGV ) {
@@ -42,10 +43,9 @@ my %STATS = (
size => 7,
);
-# Figure out the SHA algorithm to use; defaults to sha256, but can be overriden
-# by setting CHECKEM_ALG in the environment to e.g. "sha1", which is slightly
-# faster but technically broken in practice since early 2017
-my $alg = $ENV{CHECKEM_ALG} // 'sha256';
+# Figure out the Digest algorithm to use; defaults to SHA-256, but can be
+# overriden by setting CHECKEM_ALG in the environment
+my $alg = $ENV{CHECKEM_ALG} // 'SHA-256';
# Start a hash of filesizes to file names/stats...
my %sizes;
@@ -96,7 +96,12 @@ 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
- ( $dig //= Digest::SHA->new($alg) )->addfile( $f->{name} );
+ open my $fh, '<', $f->{name}
+ or croak 'Failed to open file';
+ binmode $fh;
+ ( $dig //= Digest->new($alg) )->addfile($fh);
+ close $fh
+ or croak 'Failed to close file';
push @{ $sums{ $dig->digest() } }, $f;
}
}