summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurélien Lefebvre <alefebvre@mandriva.com>2009-08-13 15:23:05 +0000
committerAurélien Lefebvre <alefebvre@mandriva.com>2009-08-13 15:23:05 +0000
commit3ae0d274efa9cda29f289b3e65f2c664d9a334eb (patch)
tree99a28a927299f931b322d21bdcd830df9ab4fcb9
parent8881a54f45f68ad95272c290e20e8bcef1ed4ec1 (diff)
downloadperl-MDK-Common-3ae0d274efa9cda29f289b3e65f2c664d9a334eb.tar
perl-MDK-Common-3ae0d274efa9cda29f289b3e65f2c664d9a334eb.tar.gz
perl-MDK-Common-3ae0d274efa9cda29f289b3e65f2c664d9a334eb.tar.bz2
perl-MDK-Common-3ae0d274efa9cda29f289b3e65f2c664d9a334eb.tar.xz
perl-MDK-Common-3ae0d274efa9cda29f289b3e65f2c664d9a334eb.zip
- Call fsync after writing to ensure that files are written
-rw-r--r--lib/MDK/Common/File.pm7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/MDK/Common/File.pm b/lib/MDK/Common/File.pm
index 5227391..812d74f 100644
--- a/lib/MDK/Common/File.pm
+++ b/lib/MDK/Common/File.pm
@@ -135,6 +135,7 @@ L<MDK::Common>
=cut
+use File::Sync qw(fsync);
use Exporter;
our @ISA = qw(Exporter);
@@ -148,9 +149,9 @@ sub cat_utf8 { my @l = map { my $F; open($F, '<:utf8', $_) ? <$F> : () } @_; wan
sub cat_or_die { open(my $F, '<', $_[0]) or die "can't read file $_[0]: $!\n"; my @l = <$F>; wantarray() ? @l : join '', @l }
sub cat_utf8_or_die { open(my $F, '<:utf8', $_[0]) or die "can't read file $_[0]: $!\n"; my @l = <$F>; wantarray() ? @l : join '', @l }
sub cat__ { my ($f) = @_; my @l = <$f>; wantarray() ? @l : join '', @l }
-sub output { my $f = shift; open(my $F, ">$f") or die "output in file $f failed: $!\n"; print $F $_ foreach @_; 1 }
-sub output_utf8 { my $f = shift; open(my $F, '>:utf8', $f) or die "output in file $f failed: $!\n"; print $F $_ foreach @_; 1 }
-sub append_to_file { my $f = shift; open(my $F, ">>$f") or die "output in file $f failed: $!\n"; print $F $_ foreach @_; 1 }
+sub output { my $f = shift; open(my $F, ">$f") or die "output in file $f failed: $!\n"; print $F $_ foreach @_; fsync($F); 1 }
+sub output_utf8 { my $f = shift; open(my $F, '>:utf8', $f) or die "output in file $f failed: $!\n"; print $F $_ foreach @_; fsync($F); 1 }
+sub append_to_file { my $f = shift; open(my $F, ">>$f") or die "output in file $f failed: $!\n"; print $F $_ foreach @_; fsync($F); 1 }
sub output_p { my $f = shift; mkdir_p(dirname($f)); output($f, @_) }
sub output_with_perm { my ($f, $perm, @l) = @_; mkdir_p(dirname($f)); output($f, @l); chmod $perm, $f }
sub linkf { unlink $_[1]; link $_[0], $_[1] }