254 |
warn "## open( $file, $mode ) pending: ", $pending->{$file}->{open}, " mode $mode: ", dump( $mode_desc )," $path [", -s $path, "]\n" if $debug; |
warn "## open( $file, $mode ) pending: ", $pending->{$file}->{open}, " mode $mode: ", dump( $mode_desc )," $path [", -s $path, "]\n" if $debug; |
255 |
|
|
256 |
my $fh; |
my $fh; |
257 |
|
my $rv = 0; |
258 |
|
|
259 |
|
if ( ! -w $path ) { |
260 |
|
my $old_mode = (stat $path)[2]; |
261 |
|
my $new_mode = $old_mode | 0600; |
262 |
|
chmod $new_mode, $path || confess "can't chmod $new_mode $path"; |
263 |
|
warn "### modify mode $old_mode -> $new_mode for $path\n"; |
264 |
|
$pending->{$file}->{mode} = $old_mode; |
265 |
|
} |
266 |
|
|
267 |
if ( sysopen($fh , $path, $mode) ) { |
if ( sysopen($fh , $path, $mode) ) { |
268 |
close($fh) || confess "can't close $path: $!"; |
close($fh) || confess "can't close $path: $!"; |
269 |
warn "<<< sysopen $path [", -e $path ? -s $path : 'new' , "]\n"; |
warn "<<< sysopen $path [", -e $path ? -s $path : 'new' , "]\n"; |
270 |
$pending->{$file}->{open}++; |
$pending->{$file}->{open}++; |
|
return 0; |
|
271 |
} else { |
} else { |
272 |
warn "ERROR: can't open $path -- $!"; |
warn "ERROR: can't open $path -- $!"; |
273 |
return -$!; |
$rv = -$!; |
274 |
} |
} |
275 |
|
|
276 |
|
return $rv; |
277 |
|
|
278 |
} |
} |
279 |
|
|
280 |
sub x_read { |
sub x_read { |
477 |
|
|
478 |
$pending->{$file}->{open}--; |
$pending->{$file}->{open}--; |
479 |
if ( $pending->{$file}->{open} == 0 ) { |
if ( $pending->{$file}->{open} == 0 ) { |
480 |
warn "## cleanup pending $file [", -s fixup($file), "]\n" if $debug; |
|
481 |
|
my $path = fixup( $file ); |
482 |
|
|
483 |
|
if ( my $old_mode = $pending->{$file}->{mode} ) { |
484 |
|
chmod $old_mode, $path || confess "can't chmod $old_mode $path"; |
485 |
|
warn "### restored mode $old_mode $path\n"; |
486 |
|
|
487 |
|
} |
488 |
|
|
489 |
|
warn "## cleanup pending $file [", -s $path, "]\n" if $debug; |
490 |
delete( $pending->{$file} ); |
delete( $pending->{$file} ); |
491 |
} |
} |
492 |
|
|