--- fuse-comp.pl 2007/07/09 22:44:20 25 +++ fuse-comp.pl 2007/07/10 00:22:00 27 @@ -42,13 +42,17 @@ my $pending; +sub real_name { + my ( $dir, $name ) = @_; + if ( -e "$dir/${name}.gz" ) { + return "${name}.gz"; + } + return $name; +} + sub fixup { my ( $path ) = @_; - my $full = $mount->{from} . '/' . $path; - if ( -e $full . '.gz' ) { - return $full . '.gz'; - } - return $full; + return $mount->{from} . '/' . real_name( $mount->{from}, $path ); } sub original_name { @@ -166,7 +170,7 @@ $pending->{$file}->{path} = $path; return 0; } else { - warn "ERROR: can't open $path : $!"; + warn "ERROR: can't open $path -- $!"; return -$!; } @@ -194,7 +198,6 @@ sub x_write { my ($file,$buf,$off) = @_; - $pending->{$file}->{write}++; my $rv; my $path = fixup($file); @@ -202,20 +205,25 @@ 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_readlink { return readlink(fixup(shift)); } + sub x_unlink { my $file = shift; my $path = fixup( $file ); @@ -235,7 +243,36 @@ return 0; } -sub x_symlink { return symlink(shift,fixup(shift)) ? 0 : -$!; } +sub x_symlink { + my ($from,$to) = @_; + + my $from_path = $from; #fixup( $from ); + my $to_path = fixup( $to ); + + my $rv = symlink( $from_path, $to_path ) ? 0 : -$!; + warn "# symlink( $from_path -> $to_path ) = $rv\n" if $debug; + + my $tmp = $mount->{tmp} . '/' . $from; + if ( -e $tmp ) { + my $tmp_to = $mount->{$tmp} . '/' . $to; + symlink( $tmp, $tmp_to ) || confess "can't symlink $tmp -> $tmp_to: $!"; + } + return $rv; +} + +sub x_link { + my ($from,$to) = @_; + + my $from_path = fixup($from); + my $to_path = fixup($to); + $to_path .= '.gz' if ( $from_path =~ m/\.gz$/ && $to_path !~ m/\.gz$/ ); + + my $rv = link( $from_path, $to_path ) ? 0 : -$!; + + warn "# link( $from_path -> $to_path ) = $rv\n" if $debug; + + return $rv; +} sub x_rename { my ($old,$new) = @_; @@ -269,17 +306,20 @@ return $err; } -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; } @@ -301,6 +341,10 @@ } warn "## truncate( $file $size ) $path [", -s $path, "] = $rv\n" if $debug; $pending->{$file}->{write}++; + + my $tmp = $mount->{tmp} . '/' . $file; + truncate( $tmp, $size ) if -e $tmp; + return $rv; } sub x_utime { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; } @@ -344,13 +388,13 @@ } if ( $file =~ $skip_extensions_regex ) { - warn "release $file [",-s $path,"] skipped compression\n"; + warn "release $path [",-s $path,"] skipped compression\n"; file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); } elsif ( -s $path < $min_compress_size ) { - warn "release $file [",-s $path,"] uncompressed, too small\n"; + warn "release $path [",-s $path,"] uncompressed, too small\n"; file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); } else { - warn "release $file [",-s $path,"] compressing\n"; + warn "release $path [",-s $path,"] compressing\n"; my $comp = $dest . '.gz'; file_copy( '<', $path, '>:gzip', $comp ); @@ -359,11 +403,11 @@ if ( $size_path <= $size_comp ) { warn ">>> $size_path <= $size_comp leaving uncompressed\n"; - unlink $comp || warn "can't reamove: $comp: $!"; + unlink $comp || confess "can't remove: $comp: $!"; } else { warn ">>> compressed $size_path -> $size_comp ",int(($size_comp * 100) / $size_path),"%\n"; # FIXME add timeout to remove uncompressed version? - unlink $path || warn "can't remove $path: $!"; + unlink $path || confess "can't remove $path: $!"; } } } else {