From 5aea82852618d987d2994fe0bc4a3faa88132878 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 29 May 2012 18:14:13 +1200 Subject: Use Digest::MD5 instead, one less binary --- clubber | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/clubber b/clubber index 9f50bec..ade101d 100755 --- a/clubber +++ b/clubber @@ -38,14 +38,6 @@ if (!$ldd) { error("Couldn't find ldd in your \$PATH."); } -# -# Check md5sum is available. -# -chomp(my $md5sum = `which md5sum`); -if (!$md5sum) { - error("Couldn't find md5sum in your \$PATH."); -} - # # Check options. # @@ -116,13 +108,50 @@ if ($chroot) { # foreach my $library (keys(%$libraries)) { my $directory = dirname($library); + + # + # If the directory doesn't exist, flag it for creation. + # if (!-d "${chroot}${directory}") { $directories->{$directory} = 1; } - if (-f "${chroot}{$library}") { - if (qx/${md5sum} ${library}/ ne qx/${md5sum} ${chroot}${library}/) { + + # + # If the library exists, we need to see if it's the same as our source + # library. + # + if (-f "${chroot}${library}") { + + # + # Get MD5 checksum of source library. + # + open(my $src, "<", $library) + or error("Couldn't read file %s to checksum it.", $library); + binmode($src); + my $src_checksum = Digest::MD5->new->addfile($src)->hexdigest; + close($src); + + # + # Get MD5 checksum of library presently occupying the path to + # which we intend to copy this library. + # + open(my $dst, "<", "${chroot}${library}") + or error("Couldn't read file %s to checksum it.", "${chroot}${library}"); + binmode($dst); + my $dst_checksum = Digest::MD5->new->addfile($dst)->hexdigest; + close($dst); + + # + # Compare checksums; if they're different, we need to copy the + # library in. + # + if ($src_checksum ne $dst_checksum) { $imports->{$library} = 1; } + + # + # The library doesn't exist, so we need to copy it in. + # } else { $imports->{$library} = 1; } -- cgit v1.2.3