--- VRac.pm 2007/08/05 14:08:01 148 +++ VRac.pm 2007/08/05 17:28:55 156 @@ -3,7 +3,7 @@ use warnings; use strict; -use Carp qw/confess croak/; +use Carp qw/confess croak cluck carp/; use File::Slurp; use Data::Dump qw/dump/; @@ -201,9 +201,21 @@ my $path = shift || confess "no path?"; my $bytes = join('', @_); + my $size = -s $path || 0; + my $len = length($bytes); + open(my $fh, '>>', $path) || confess "can't open $path: $!"; + print($fh $bytes); + my $pos = tell($fh); + + my $expected = $size + $len; + if ( $pos != $expected ) { + carp "BUG: file grows too big got $pos, expected $expected !"; + truncate $fh, $expected; + } + + close($fh); - print $fh $bytes; warn sprintf("## append_to_file('%s',%s)\n", $path, dump($bytes)); }