--- fuse-comp.pl 2007/07/16 07:51:20 34 +++ fuse-comp.pl 2007/07/16 08:24:08 35 @@ -254,17 +254,27 @@ warn "## open( $file, $mode ) pending: ", $pending->{$file}->{open}, " mode $mode: ", dump( $mode_desc )," $path [", -s $path, "]\n" if $debug; my $fh; + my $rv = 0; + + if ( ! -w $path ) { + my $old_mode = (stat $path)[2]; + my $new_mode = $old_mode | 0600; + chmod $new_mode, $path || confess "can't chmod $new_mode $path"; + warn "### modify mode $old_mode -> $new_mode for $path\n"; + $pending->{$file}->{mode} = $old_mode; + } if ( sysopen($fh , $path, $mode) ) { close($fh) || confess "can't close $path: $!"; warn "<<< sysopen $path [", -e $path ? -s $path : 'new' , "]\n"; $pending->{$file}->{open}++; - return 0; } else { warn "ERROR: can't open $path -- $!"; - return -$!; + $rv = -$!; } + return $rv; + } sub x_read { @@ -467,7 +477,16 @@ $pending->{$file}->{open}--; if ( $pending->{$file}->{open} == 0 ) { - warn "## cleanup pending $file [", -s fixup($file), "]\n" if $debug; + + my $path = fixup( $file ); + + if ( my $old_mode = $pending->{$file}->{mode} ) { + chmod $old_mode, $path || confess "can't chmod $old_mode $path"; + warn "### restored mode $old_mode $path\n"; + + } + + warn "## cleanup pending $file [", -s $path, "]\n" if $debug; delete( $pending->{$file} ); }