summaryrefslogtreecommitdiff
path: root/build-aux/fetch.pl
diff options
context:
space:
mode:
Diffstat (limited to 'build-aux/fetch.pl')
-rwxr-xr-xbuild-aux/fetch.pl30
1 files changed, 21 insertions, 9 deletions
diff --git a/build-aux/fetch.pl b/build-aux/fetch.pl
index b31eade8..b8abe1b7 100755
--- a/build-aux/fetch.pl
+++ b/build-aux/fetch.pl
@@ -43,7 +43,6 @@ our %to_fetch = (
'build-aux' => {
automake => [
'lib/install-sh',
- 'lib/mdate-sh',
],
config => [
'config.guess',
@@ -154,13 +153,23 @@ sub savannah_url($$)
# slurp ($filename)
# Read the contents of $filename into a scalar and return them.
+# If $filename does not exist, return undef; any other error is fatal.
sub slurp ($)
{
my ($filename) = @_;
local $/; # engage slurp mode
- open my $fh, '<', $filename
- or die "$filename: $!\n";
- return scalar <$fh>;
+ if (open my $fh, '<', $filename)
+ {
+ return scalar <$fh>;
+ }
+ elsif ($!{ENOENT})
+ {
+ return undef;
+ }
+ else
+ {
+ die "$filename: $!\n";
+ }
}
@@ -174,7 +183,7 @@ sub replace_if_change ($$$)
my ($file, $newcontents, $quiet) = @_;
my $oldcontents = slurp $file;
- if ($oldcontents eq $newcontents)
+ if (defined $oldcontents && $oldcontents eq $newcontents)
{
print STDERR "$file is unchanged\n" unless $quiet;
return;
@@ -191,10 +200,13 @@ sub replace_if_change ($$$)
close $tmp_fh
or die "$0: writing to $tmp_name: $!\n";
- # Preserve the permissions of the original file.
- my $st = stat $file;
- chmod (S_IMODE ($st->mode), $tmp_name)
- or die "$0: setting permissions on $tmp_name: $!\n";
+ # Preserve the permissions of the original file, if it exists.
+ if (defined $oldcontents)
+ {
+ my $st = stat $file;
+ chmod (S_IMODE ($st->mode), $tmp_name)
+ or die "$0: setting permissions on $tmp_name: $!\n";
+ }
rename $tmp_name, $file
or die "$0: rename($tmp_name, $file): $!\n";