/[fuse-comp]/fuse-comp.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /fuse-comp.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 19 by dpavlin, Mon Jul 9 15:59:57 2007 UTC revision 20 by dpavlin, Mon Jul 9 16:20:07 2007 UTC
# Line 19  my $mount = { Line 19  my $mount = {
19          tmp             => '/dev/shm/comp',          tmp             => '/dev/shm/comp',
20  };  };
21    
22  my $debug = 0;  my $debug = shift @ARGV;
23    
24  my $skip_extensions_regex = qr/\.(?:sw[a-z]|gif|png|jpeg|jpg|avi|rar|zip|bz2|gz|tgz|avi|mpeg|mpg|tmp|temp)$/i;  my $skip_extensions_regex = qr/\.(?:sw[a-z]|gif|png|jpeg|jpg|avi|rar|zip|bz2|gz|tgz|avi|mpeg|mpg|tmp|temp)$/i;
25    
# Line 232  sub x_rename { Line 232  sub x_rename {
232                  rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!";                  rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!";
233          }          }
234    
235            if (defined( $pending->{$old} )) {
236                    $pending->{$new} = $pending->{$old};
237    
238                    my $path = $pending->{$old}->{path};
239                    $path =~ s/\Q$old\E/$new/;
240                    $pending->{$new}->{path} = $path;
241    
242                    delete( $pending->{$old} );
243            }
244    
245          return $err;          return $err;
246  }  }
247  sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! }  sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! }
# Line 302  sub x_release { Line 312  sub x_release {
312                  }                  }
313    
314                  if ( $file =~ $skip_extensions_regex ) {                  if ( $file =~ $skip_extensions_regex ) {
315                          warn "release $file $mode -- uncompressed\n";                          warn "release $file [",-s $path,"] skipped compression\n";
316                          file_copy( '<', $path, '>', $dest ) if ( $path ne $dest );                          file_copy( '<', $path, '>', $dest ) if ( $path ne $dest );
317                  } elsif ( -s $path < $min_compress_size ) {                  } elsif ( -s $path < $min_compress_size ) {
318                          warn "release $file -- uncompressed, too small [", -s $path, "]\n";                          warn "release $file [",-s $path,"] uncompressed, too small\n";
319                          file_copy( '<', $path, '>', $dest ) if ( $path ne $dest );                          file_copy( '<', $path, '>', $dest ) if ( $path ne $dest );
320                  } else {                  } else {
321                          warn "release $file $mode -- compressing\n";                          warn "release $file [",-s $path,"] compressing\n";
322    
323                            my $comp = $dest . '.gz';
324                            file_copy( '<', $path, '>:gzip', $comp );
325    
326                          file_copy( '<', $path, '>:gzip', $dest . '.gz' );                          my ( $size_path, $size_comp ) = ( -s $path, -s $comp );
327    
328                          # FIXME add timeout to remove uncompressed version?                          if ( $size_path <= $size_comp ) {
329                          # FIXME leave uncompressed file if smaller than compressed                                  warn ">>> $size_path <= $size_comp leaving uncompressed\n";
330                          unlink $path || warn "can't remove $path: $!";                                  unlink $comp || warn "can't reamove: $comp: $!";
331                            } else {
332                                    warn ">>> compressed $size_path -> $size_comp ",int(($size_comp * 100) / $size_path),"%\n";
333                                    # FIXME add timeout to remove uncompressed version?
334                                    unlink $path || warn "can't remove $path: $!";
335                            }
336                  }                  }
337          } else {          } else {
338                  warn "release $file, but still used ", $pending->{$file}->{open} , " times, delaying compression\n";                  warn "release $file, but still used ", $pending->{$file}->{open} , " times, delaying compression\n";

Legend:
Removed from v.19  
changed lines
  Added in v.20

  ViewVC Help
Powered by ViewVC 1.1.26