diff options
author | Olivier Blin <blino@mageia.org> | 2011-04-12 11:36:52 +0000 |
---|---|---|
committer | Olivier Blin <blino@mageia.org> | 2011-04-12 11:36:52 +0000 |
commit | d8a7fd2813dccec1f2863700ce4ef0f3e5a12c30 (patch) | |
tree | 6d213d68795ca3f1d0a8c28f6b34411d07c05439 /lib/MDK/Common/File.pm | |
parent | e2c864512f4e0643422ebd4a8af1e333b67be424 (diff) | |
download | perl-MDK-Common-d8a7fd2813dccec1f2863700ce4ef0f3e5a12c30.tar perl-MDK-Common-d8a7fd2813dccec1f2863700ce4ef0f3e5a12c30.tar.gz perl-MDK-Common-d8a7fd2813dccec1f2863700ce4ef0f3e5a12c30.tar.bz2 perl-MDK-Common-d8a7fd2813dccec1f2863700ce4ef0f3e5a12c30.tar.xz perl-MDK-Common-d8a7fd2813dccec1f2863700ce4ef0f3e5a12c30.zip |
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)
Diffstat (limited to 'lib/MDK/Common/File.pm')
-rw-r--r-- | lib/MDK/Common/File.pm | 10 |
1 files changed, 7 insertions, 3 deletions
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); } } |