--- fuse-comp.pl 2007/07/09 23:28:58 26 +++ 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 { @@ -218,7 +222,8 @@ 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 ); @@ -238,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) = @_; @@ -272,7 +306,6 @@ return $err; } -sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! } sub x_chown { my ($file,$uid,$gid) = @_; @@ -308,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:-$!; } @@ -351,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 ); @@ -366,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 {