# HG changeset patch # User Matthias Förste # Date 1306749510 -7200 # Node ID 3ba69372dec35a1565917f23d6b258aa354e61f9 # Parent 942ef82c967308a2f042189f1eb1437807b81684 write old lines (not changed ones) to backup of zone config snippet diff -r 942ef82c9673 -r 3ba69372dec3 bin/update-serial --- 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 = ; # 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': $!";