summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--lib/MDK/Common/File.pm3
2 files changed, 5 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 7b2e039..9254060 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,6 @@
+- substInFile:
+ o ensure we keep old file as file.bak until we wrote new file
+
Version 1.2.20 - 13 August 2009, by Aurelien Lefebvre
- Call fsync after writing to ensure that files are written
diff --git a/lib/MDK/Common/File.pm b/lib/MDK/Common/File.pm
index 812d74f..71fe71c 100644
--- a/lib/MDK/Common/File.pm
+++ b/lib/MDK/Common/File.pm
@@ -282,13 +282,14 @@ sub substInFile(&@) {
}
if (-s $file) {
local @ARGV = $file;
- local $^I = '';
+ local $^I = '.bak';
local $_;
while (<>) {
$_ .= "\n" if eof && !/\n/;
&$f($_);
print;
}
+ unlink "$file$^I"; # remove old backup now that we'have closed new file
} else {
local *F; my $old = select F; # that way eof return true
local $_ = '';