--- fuse-comp.pl 2007/07/09 15:59:57 19 +++ fuse-comp.pl 2007/07/09 16:20:07 20 @@ -19,7 +19,7 @@ tmp => '/dev/shm/comp', }; -my $debug = 0; +my $debug = shift @ARGV; my $skip_extensions_regex = qr/\.(?:sw[a-z]|gif|png|jpeg|jpg|avi|rar|zip|bz2|gz|tgz|avi|mpeg|mpg|tmp|temp)$/i; @@ -232,6 +232,16 @@ rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!"; } + if (defined( $pending->{$old} )) { + $pending->{$new} = $pending->{$old}; + + my $path = $pending->{$old}->{path}; + $path =~ s/\Q$old\E/$new/; + $pending->{$new}->{path} = $path; + + delete( $pending->{$old} ); + } + return $err; } sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! } @@ -302,20 +312,27 @@ } if ( $file =~ $skip_extensions_regex ) { - warn "release $file $mode -- uncompressed\n"; + warn "release $file [",-s $path,"] skipped compression\n"; file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); } elsif ( -s $path < $min_compress_size ) { - warn "release $file -- uncompressed, too small [", -s $path, "]\n"; + warn "release $file [",-s $path,"] uncompressed, too small\n"; file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); } else { - warn "release $file $mode -- compressing\n"; + warn "release $file [",-s $path,"] compressing\n"; + my $comp = $dest . '.gz'; + file_copy( '<', $path, '>:gzip', $comp ); - file_copy( '<', $path, '>:gzip', $dest . '.gz' ); + my ( $size_path, $size_comp ) = ( -s $path, -s $comp ); - # FIXME add timeout to remove uncompressed version? - # FIXME leave uncompressed file if smaller than compressed - unlink $path || warn "can't remove $path: $!"; + if ( $size_path <= $size_comp ) { + warn ">>> $size_path <= $size_comp leaving uncompressed\n"; + unlink $comp || warn "can't reamove: $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: $!"; + } } } else { warn "release $file, but still used ", $pending->{$file}->{open} , " times, delaying compression\n";