diff options
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | lib/MDK/Common/File.pm | 10 |
2 files changed, 12 insertions, 3 deletions
@@ -1,3 +1,8 @@ +- substInFile: fix writing to zero-sized or nonexistent files (#460), + eof does not seem to return true anymore for filehandles vivified + through select (behavior change seems introduced by upstream perl + commit 32e653230c7ccc7fa595b1ab68502c6eb66ff980) + Version 1.2.27 - 2 February 2011, by Eugeni Dodonov - add cp_afx command diff --git a/lib/MDK/Common/File.pm b/lib/MDK/Common/File.pm index a44c479..4dbb99d 100644 --- a/lib/MDK/Common/File.pm +++ b/lib/MDK/Common/File.pm @@ -342,11 +342,15 @@ sub substInFile(&@) { fsync($F); 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 + #- special handling for zero-sized or nonexistent files + #- because while (<>) will not do any iteration + open(my $F, "+> $file") or return; + #- "eof" without an argument uses the last file read + my $dummy = <$F>; local $_ = ''; &$f($_); - select $old; - eval { output($file, $_) }; + print $F $_; + fsync($F); } } |