--- fuse-comp.pl 2007/07/09 11:12:48 13 +++ fuse-comp.pl 2007/07/09 15:41:01 18 @@ -146,11 +146,12 @@ rdwr => $mode && O_RDWR, append => $mode && O_APPEND, create => $mode && O_CREAT, + trunc => $mode && O_TRUNC, }; - warn "# open( $file, $mode ) pending: ", $pending->{$file}->{open}, " mode: ", dump( $mode_desc ),"\n"; + my $path = fixup($file); + warn "# open( $file, $mode ) pending: ", $pending->{$file}->{open}, " mode $mode: ", dump( $mode_desc )," $path [", -s $path, "]\n"; my $fh; - my $path = fixup($file); my $tmp = $mount->{tmp} . '/' . $file; if ( -e $tmp ) { $path = $tmp; @@ -161,7 +162,7 @@ file_copy( '<:gzip', $path, '>', $tmp ); $path = $tmp; } - warn ">>> open abs path: $path [", -s $path, "]\n"; + warn ">>> open abs path: $path [", -e $path ? -s $path : 'new' , "]\n"; return -$! unless sysopen($fh , $path, $mode); close($fh); @@ -202,7 +203,7 @@ return -ENOSYS() unless open($fh,'+<',$pending->{$file}->{path}); if($rv = seek( $fh ,$off,SEEK_SET)) { $rv = print( $fh $buf ); - warn "## ", $pending->{$file}->{path}, " $off ",length( $buf ), "\n" if $debug; + warn "## write ", $pending->{$file}->{path}, " $off ",length( $buf ), "\n" if $debug; } $rv = -ENOSYS() unless $rv; close($fh); @@ -217,9 +218,20 @@ sub x_symlink { return symlink(shift,fixup(shift)) ? 0 : -$!; } sub x_rename { - my ($old) = fixup(shift); - my ($new) = fixup(shift); - my ($err) = rename($old,$new) ? 0 : -ENOENT(); + my ($old,$new) = @_; + my $old_path = fixup($old); + my $new_path = fixup($new); + $new_path .= '.gz' if ( $old_path =~ m/\.gz$/ && $new_path !~ m/\.gz$/ ); + + my $err = rename($old_path,$new_path) ? 0 : -ENOENT(); + warn "## rename( $old_path => $new_path ) = $err\n"; + + my $tmp = $mount->{tmp} . '/' . $old; + if ( -e $tmp ) { + my $new_tmp = $mount->{tmp} . '/' . $new; + rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!"; + } + return $err; } sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! } @@ -243,7 +255,19 @@ return $err; } -sub x_truncate { return truncate(fixup(shift),shift) ? 0 : -$! ; } +sub x_truncate { + my ( $file,$size ) = @_; + my $path = fixup($file); + my $rv = truncate( $path, $size ) ? 0 : -$! ; + if ( $path =~ m/\.gz$/ ) { + my $no_gz = $path; + $no_gz =~ s/\.gz$//; + rename $path, $no_gz || confess "can't rename $path -> $no_gz: $!"; + } + warn "## truncate( $file $size ) $path [", -s $path, "]\n"; + $pending->{$file}->{write}++; + return $rv; +} sub x_utime { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; } sub x_mkdir { my ($name, $perm) = @_; return 0 if mkdir(fixup($name),$perm); return -$!; } @@ -290,6 +314,7 @@ file_copy( '<', $path, '>:gzip', $dest . '.gz' ); # FIXME add timeout to remove uncompressed version? + # FIXME leave uncompressed file if smaller than compressed unlink $path || warn "can't remove $path: $!"; } } else {