summaryrefslogtreecommitdiff
path: root/regen_lib.pl
diff options
context:
space:
mode:
authorJim Cromie <jcromie@cpan.org>2008-03-11 12:16:14 -0600
committerNicholas Clark <nick@ccl4.org>2008-03-15 17:30:19 +0000
commitb6b9a09997c80269af874aff41936e014ed728f7 (patch)
tree461c4ca1dd9e80df65f170edfb6797c4eafe2a22 /regen_lib.pl
parentb2866d4731cba846ea38e592b806a44f665742ca (diff)
downloadperl-b6b9a09997c80269af874aff41936e014ed728f7.tar.gz
Re: [patch] refine make regen to be more selective
Message-ID: <47D720CE.7060004@gmail.com> Date: Tue, 11 Mar 2008 18:16:14 -0600 p4raw-id: //depot/perl@33537
Diffstat (limited to 'regen_lib.pl')
-rw-r--r--regen_lib.pl33
1 files changed, 33 insertions, 0 deletions
diff --git a/regen_lib.pl b/regen_lib.pl
index 1c830a2cdc..896a9ad0fe 100644
--- a/regen_lib.pl
+++ b/regen_lib.pl
@@ -15,6 +15,24 @@ if ($Is_NetWare) {
$Needs_Write = $Is_OS2 || $Is_W32 || $Is_Cygwin || $Is_NetWare;
+eval "use Digest::MD5 'md5'; 1;"
+ or warn "Digest::MD5 unavailable, doing unconditional regen\n";
+
+sub cksum {
+ my $pl = shift;
+ my ($buf, $cksum);
+ local *FH;
+ if (open(FH, $pl)) {
+ local $/;
+ $buf = <FH>;
+ $cksum = defined &md5 ? md5($buf) : 0;
+ close FH;
+ } else {
+ warn "$0: $pl: $!\n";
+ }
+ return $cksum;
+}
+
sub safer_unlink {
my @names = @_;
my $cnt = 0;
@@ -38,8 +56,23 @@ sub safer_rename_silent {
rename $from, $to;
}
+sub safer_rename_always {
+ my ($from, $to) = @_;
+ safer_rename_silent($from, $to) or die "renaming $from to $to: $!";
+}
+
sub safer_rename {
my ($from, $to) = @_;
+
+ my $fc = cksum($from);
+ my $tc = cksum($to);
+
+ if ($fc and $fc eq $tc) {
+ warn "no changes between '$from' & '$to'\n";
+ safer_unlink($from);
+ return;
+ }
+ warn "changed '$from' to '$to'\n";
safer_rename_silent($from, $to) or die "renaming $from to $to: $!";
}
1;