--- a/bin/update-serial Mon May 30 11:48:32 2011 +0200
+++ b/bin/update-serial Mon May 30 11:58:30 2011 +0200
@@ -332,20 +332,25 @@
my $de = dnssec_enabled $z, "$md/$config{indexzone}/$config{indexzone}";
my $suf = $de ? '.signed' : '';
# TODO: assuming that paths in $md and in zone config snippets match somehow
- my $zp = "$z/$z$suf";
+ my $zr = qr{\Q$z/$z$suf\E$};
my $zf = "$md/$z/$z$suf";
my ($files, $changed) = (0, 0);
my $czf;
open C, "+<$cf" or die "Cant't open '$cf': $!";
my @lines = <C>; # TODO: deal with race condition?
+ my @oldlines;
my ($mode, $uid, $gid, $atime, $mtime) = (stat C)[2, 4, 5, 8, 9] or die "Can't stat: $!";
$mode &= 07777;
for (@lines) {
next unless /^\s*file\s+"([^"]*)"\s*;\s*$/;
$czf = $1;
$files++;
- $_ = qq(\tfile "$zf";\n) and $changed++ unless $czf =~ m#\Q$z/$z$suf\E$#;
+ unless ($czf =~ /$zr/) {
+ $changed++;
+ @oldlines or @oldlines = @lines;
+ $_ = qq(\tfile "$zf";\n);
+ }
}
die "Multiple file statements found in '$cf' (maybe inside multiline comments)" if $files > 1;
@@ -354,7 +359,7 @@
# file statement in config snippet doesnt match, so we make a backup first and write a new config
my $cb = "$cf.bak";
open B, ">$cb" or die "Can't open '$cb': $!";
- print B @lines;
+ print B @oldlines;
close B;
chown $uid, $gid, $cb or die "Can't 'chown $uid, $gid, $cb': $!";
chmod $mode, $cb or die "Can't 'chmod $mode, $cb': $!";