--- fuse-comp.pl 2007/07/09 21:57:11 24 +++ fuse-comp.pl 2007/07/09 23:28:58 26 @@ -76,20 +76,6 @@ return unpack("L", $buff); } -sub unlink_all { - my $file = shift; - warn "# unlink_all( $file )\n"; - - my $path = fixup( $file ); - unlink $path || return 0; - - my $tmp = $mount->{tmp} . '/' . $file; - unlink $tmp if ( -e $tmp ); - - delete( $pending->{$file} ); - return 1; -} - sub x_getattr { my ($file) = fixup(shift); my (@list) = lstat($file); @@ -180,7 +166,7 @@ $pending->{$file}->{path} = $path; return 0; } else { - warn "ERROR: can't open $path : $!"; + warn "ERROR: can't open $path -- $!"; return -$!; } @@ -207,7 +193,7 @@ sub x_write { my ($file,$buf,$off) = @_; - $pending->{$file}->{write}++; + my $rv; my $path = fixup($file); @@ -215,21 +201,42 @@ return -ENOENT() unless -e $path; + $path = $pending->{$file}->{path} || confess "no path for $file in ", dump( $pending ); + confess "write into non-existant $path for $file: $!" unless -e $path; + my $fh = new IO::File; - return -ENOSYS() unless open($fh,'+<',$pending->{$file}->{path}); + return -ENOSYS() unless open($fh,'+<',$path); if($rv = seek( $fh ,$off,SEEK_SET)) { $rv = print( $fh $buf ); - warn "## write ", $pending->{$file}->{path}, " $off ",length( $buf ), "\n" if $debug; + warn "## write $path offset $off [",length( $buf ), "]\n" if $debug; + $pending->{$file}->{write}++; } $rv = -ENOSYS() unless $rv; - close($fh); + close($fh) || warn "can't close $path: $!"; return length($buf); } sub err { return (-shift || -$!) } sub x_readlink { return readlink(fixup(shift)); } -sub x_unlink { return unlink_all( shift ) ? 0 : -$! } +sub x_unlink { + my $file = shift; + my $path = fixup( $file ); + + if ( $file =~ m#\Q/.fuse_hidden\E# ) { + return unlink $path ? 0 : -$1; + } + + warn "# unlink( $file )\n"; + + unlink $path || return 0; + + my $tmp = $mount->{tmp} . '/' . $file; + unlink $tmp if ( -e $tmp ); + + delete( $pending->{$file} ); + return 0; +} sub x_symlink { return symlink(shift,fixup(shift)) ? 0 : -$!; } @@ -244,8 +251,12 @@ 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 : $!"; + if ( $new =~ m#\Q/.fuse_hidden\E# ) { + unlink $tmp || confess "can't unlink $tmp for $new\n"; + } else { + my $new_tmp = $mount->{tmp} . '/' . $new; + rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!"; + } } if (defined( $pending->{$old} )) { @@ -254,9 +265,9 @@ my $path = $pending->{$old}->{path}; $path =~ s/\Q$old\E/$new/; $pending->{$new}->{path} = $path; - $pending->{$old}->{path} = $path; - #delete( $pending->{$old} ); + delete( $pending->{$old} ); + warn "## tweaking pending to ", dump( $pending ) if $debug; } return $err; @@ -264,14 +275,18 @@ sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! } sub x_chown { - my ($path) = fixup(shift); + my ($file,$uid,$gid) = @_; + my $path = fixup($file); print "nonexistent $path\n" unless -e $path; - my ($uid,$gid) = @_; # perl's chown() does not chown symlinks, it chowns the symlink's # target. it fails when the link's target doesn't exist, because # the stat64() syscall fails. # this causes error messages when unpacking symlinks in tarballs. my ($err) = syscall(&SYS_lchown,$path,$uid,$gid,$path) ? -$! : 0; + + my $tmp = $mount->{tmp} . '/' . $file; + syscall(&SYS_lchown,$file,$uid,$gid,$path) if -e $tmp; + return $err; } @@ -312,6 +327,13 @@ sub x_release { my ( $file, $mode ) = @_; + + if ( $file =~ m#\Q/.fuse_hidden\E# ) { + warn "release internal $file\n" if $debug; + delete( $pending->{$file} ); + return 0; + } + if ( ! defined( $pending->{$file} ) ) { warn "release $file, NO PENDING DATA\n"; return 0;