3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
use Carp qw/confess croak/; |
use Carp qw/confess croak cluck carp/; |
7 |
use File::Slurp; |
use File::Slurp; |
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
|
|
201 |
my $path = shift || confess "no path?"; |
my $path = shift || confess "no path?"; |
202 |
my $bytes = join('', @_); |
my $bytes = join('', @_); |
203 |
|
|
204 |
|
my $size = -s $path || 0; |
205 |
|
my $len = length($bytes); |
206 |
|
|
207 |
open(my $fh, '>>', $path) || confess "can't open $path: $!"; |
open(my $fh, '>>', $path) || confess "can't open $path: $!"; |
208 |
|
print($fh $bytes); |
209 |
|
my $pos = tell($fh); |
210 |
|
|
211 |
|
my $expected = $size + $len; |
212 |
|
if ( $pos != $expected ) { |
213 |
|
carp "BUG: file grows too big got $pos, expected $expected !"; |
214 |
|
truncate $fh, $expected; |
215 |
|
} |
216 |
|
|
217 |
|
close($fh); |
218 |
|
|
|
print $fh $bytes; |
|
219 |
warn sprintf("## append_to_file('%s',%s)\n", $path, dump($bytes)); |
warn sprintf("## append_to_file('%s',%s)\n", $path, dump($bytes)); |
220 |
} |
} |
221 |
|
|