aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2012-05-29 18:14:13 +1200
committerTom Ryder <tom@sanctum.geek.nz>2012-05-29 18:14:13 +1200
commit5aea82852618d987d2994fe0bc4a3faa88132878 (patch)
tree7017084a7020b191f0f9a4b26b1d5d0c6438e45a
parentTidy and comment use/modules section (diff)
downloadclubber-5aea82852618d987d2994fe0bc4a3faa88132878.tar.gz
clubber-5aea82852618d987d2994fe0bc4a3faa88132878.zip
Use Digest::MD5 instead, one less binary
-rwxr-xr-xclubber49
1 files changed, 39 insertions, 10 deletions
diff --git a/clubber b/clubber
index 9f50bec..ade101d 100755
--- a/clubber
+++ b/clubber
@@ -39,14 +39,6 @@ if (!$ldd) {
}
#
-# Check md5sum is available.
-#
-chomp(my $md5sum = `which md5sum`);
-if (!$md5sum) {
- error("Couldn't find md5sum in your \$PATH.");
-}
-
-#
# Check options.
#
my ($chroot, $dry) = ("", 0);
@@ -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;
}