/[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 30 by dpavlin, Tue Jul 10 10:48:21 2007 UTC revision 34 by dpavlin, Mon Jul 16 07:51:20 2007 UTC
# Line 30  my $mount = { Line 30  my $mount = {
30          tmp             => '/dev/shm/comp',          tmp             => '/dev/shm/comp',
31  };  };
32    
33  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/gz|gz%|\.(?:sw[a-z]|gif|png|jpeg|jpg|avi|rar|zip|bz2|tgz|avi|mpeg|mpg|tmp|temp)$/i;
34    
35  # don't compress files smaller than this  # don't compress files smaller than this
36  my $min_compress_size = 512;  my $min_compress_size = 512;
# Line 50  sub real_name { Line 50  sub real_name {
50                  confess "ASSERT: unexpected $dir/$name exists" if -e "$dir/$name";                  confess "ASSERT: unexpected $dir/$name exists" if -e "$dir/$name";
51                  return "${name}.gz";                  return "${name}.gz";
52          }          }
53          return $name;          if ( $name =~ m/\.gz$/ ) {
54                    return $name . '%';     # protect (mingle) compressed files
55            } else {
56                    return $name;
57            }
58  }  }
59    
60  sub fixup {  sub fixup {
# Line 61  sub fixup { Line 65  sub fixup {
65  sub original_name {  sub original_name {
66          my $p = shift;          my $p = shift;
67          $p =~ s/\.gz$//;          $p =~ s/\.gz$//;
68            $p =~ s/\.gz%$/.gz/;    # demungle compressed .gz files
69          return $p;          return $p;
70  };  };
71    
# Line 146  sub tmp_path { Line 151  sub tmp_path {
151                          if ( -s $path ) {                          if ( -s $path ) {
152                                  file_copy( '<:gzip', $path, '>', $tmp )                                  file_copy( '<:gzip', $path, '>', $tmp )
153                          } else {                          } else {
154                                  confess "ASSERT: filesystem corruption, $path is zero size\n";                                  confess "ASSERT: filesystem corruption, $path is zero size in ",dump( $pending );
155                          }                          }
156                          $path = $tmp;                          $path = $tmp;
157                          $op = 'created';                          $op = 'created';
# Line 155  sub tmp_path { Line 160  sub tmp_path {
160                  confess "ASSERT: open shouldn't exist for $file in ", dump( $pending ) if defined( $pending->{$file}->{open} );                  confess "ASSERT: open shouldn't exist for $file in ", dump( $pending ) if defined( $pending->{$file}->{open} );
161                  $pending->{$file}->{path} = $path;                  $pending->{$file}->{path} = $path;
162                  $pending->{$file}->{open} = 0;  # not really opened, just uncompressed                  $pending->{$file}->{open} = 0;  # not really opened, just uncompressed
163                  warn "## tmp_file( $file ) $op $path [", -s $path, "]\n";                  warn "## tmp_file( $file ) $op $path [", -s $path, "]\n" if $debug;
164          }          }
165          return $path;          return $path;
166  }  }
# Line 174  sub compress_file2path { Line 179  sub compress_file2path {
179                  } elsif ( ! $path ) {                  } elsif ( ! $path ) {
180                          $path = $pending_path;                          $path = $pending_path;
181                  } elsif ( $pending_path ne $path ) {                  } elsif ( $pending_path ne $path ) {
182                          confess "ASSERT: compressing into $path instead of $pending_path\n";                          confess "ASSERT: compressing into $path instead of $pending_path";
183                  }                  }
184          }          }
185    
# Line 203  sub compress_file2path { Line 208  sub compress_file2path {
208                  my ( $size_path, $size_comp ) = ( -s $path, -s $comp );                  my ( $size_path, $size_comp ) = ( -s $path, -s $comp );
209    
210                  if ( $size_path <= $size_comp ) {                  if ( $size_path <= $size_comp ) {
211                          warn ">>> $size_path <= $size_comp leaving uncompressed\n";                          warn ">>> $size_path <= $size_comp leaving uncompressed $dest\n";
212                          unlink $comp || confess "can't remove: $comp: $!";                          unlink $comp || confess "can't remove: $comp: $!";
213                            file_copy( '<', $path, '>', $dest ) if ( $path ne $dest );
214                  } else {                  } else {
215                          warn ">>> compressed $size_path -> $size_comp ",int(($size_comp * 100) / $size_path),"% $comp\n";                          warn ">>> compressed $size_path -> $size_comp ",int(($size_comp * 100) / $size_path),"% $comp\n";
216    
# Line 373  sub x_rename { Line 379  sub x_rename {
379          my $tmp = $mount->{tmp} . '/' . $old;          my $tmp = $mount->{tmp} . '/' . $old;
380          if ( -e $tmp ) {          if ( -e $tmp ) {
381                  if ( $new =~ m#\Q/.fuse_hidden\E# ) {                  if ( $new =~ m#\Q/.fuse_hidden\E# ) {
382                          unlink $tmp || confess "can't unlink $tmp for $new\n";                          unlink $tmp || confess "can't unlink $tmp for $new";
383                  } else {                  } else {
384                          my $new_tmp = $mount->{tmp} . '/' . $new;                          my $new_tmp = $mount->{tmp} . '/' . $new;
385                          rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!";                          rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!";

Legend:
Removed from v.30  
changed lines
  Added in v.34

  ViewVC Help
Powered by ViewVC 1.1.26