From d8a7fd2813dccec1f2863700ce4ef0f3e5a12c30 Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Tue, 12 Apr 2011 11:36:52 +0000 Subject: 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) --- lib/MDK/Common/File.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/MDK') 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); } } -- cgit v1.2.1