/[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 24 by dpavlin, Mon Jul 9 21:57:11 2007 UTC
# Line 12  use File::Path; Line 12  use File::Path;
12  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
13  use Carp qw/confess/;  use Carp qw/confess/;
14  use IO::File;  use IO::File;
15    use Getopt::Long;
16    
17    my $debug = 0;
18    my $fuse_debug = 0;
19    
20    GetOptions(
21            'debug+' => \$debug,
22            'fuse-debug+' => \$fuse_debug,
23    );
24    
25  my $mount = {  my $mount = {
26          from    => '/tmp/comp',          from    => '/tmp/comp',
# Line 19  my $mount = { Line 28  my $mount = {
28          tmp             => '/dev/shm/comp',          tmp             => '/dev/shm/comp',
29  };  };
30    
 my $debug = 0;  
   
31  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;
32    
33  # don't compress files smaller than this  # don't compress files smaller than this
# Line 159  sub x_open { Line 166  sub x_open {
166                  my $dest_path = $tmp;                  my $dest_path = $tmp;
167                  $dest_path =~ s!/[^/]+$!!;      #!vim-fix                  $dest_path =~ s!/[^/]+$!!;      #!vim-fix
168                  mkpath $dest_path unless -e $dest_path;                  mkpath $dest_path unless -e $dest_path;
169                  file_copy( '<:gzip', $path, '>', $tmp );                  if ( -s $path ) {
170                            file_copy( '<:gzip', $path, '>', $tmp )
171                    } else {
172                            warn "ERROR: filesystem corruption, $path is zero size\n";
173                    }
174                  $path = $tmp;                  $path = $tmp;
175          }          }
         warn "<<< open abs path: $path [", -e $path ? -s $path : 'new' , "]\n";  
         return -$! unless sysopen($fh , $path, $mode);  
         close($fh);  
176    
177          $pending->{$file}->{path} = $path;          if ( sysopen($fh , $path, $mode) ) {
178          return 0;                  close($fh) || confess "can't close $path: $!";
179                    warn "<<< open $path [", -e $path ? -s $path : 'new' , "]\n";
180                    $pending->{$file}->{path} = $path;
181                    return 0;
182            } else {
183                    warn "ERROR: can't open $path : $!";
184                    return -$!;
185            }
186    
187  }  }
188    
189  sub x_read {  sub x_read {
# Line 232  sub x_rename { Line 248  sub x_rename {
248                  rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!";                  rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!";
249          }          }
250    
251            if (defined( $pending->{$old} )) {
252                    $pending->{$new} = $pending->{$old};
253    
254                    my $path = $pending->{$old}->{path};
255                    $path =~ s/\Q$old\E/$new/;
256                    $pending->{$new}->{path} = $path;
257                    $pending->{$old}->{path} = $path;
258    
259                    #delete( $pending->{$old} );
260            }
261    
262          return $err;          return $err;
263  }  }
264  sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! }  sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! }
# Line 264  sub x_truncate { Line 291  sub x_truncate {
291                  $no_gz =~ s/\.gz$//;                  $no_gz =~ s/\.gz$//;
292                  rename $path, $no_gz || confess "can't rename $path -> $no_gz: $!";                  rename $path, $no_gz || confess "can't rename $path -> $no_gz: $!";
293          }          }
294          warn "## truncate( $file $size ) $path [", -s $path, "]\n";          warn "## truncate( $file $size ) $path [", -s $path, "] = $rv\n" if $debug;
295          $pending->{$file}->{write}++;          $pending->{$file}->{write}++;
296          return $rv;          return $rv;
297  }  }
# Line 302  sub x_release { Line 329  sub x_release {
329                  }                  }
330    
331                  if ( $file =~ $skip_extensions_regex ) {                  if ( $file =~ $skip_extensions_regex ) {
332                          warn "release $file $mode -- uncompressed\n";                          warn "release $file [",-s $path,"] skipped compression\n";
333                          file_copy( '<', $path, '>', $dest ) if ( $path ne $dest );                          file_copy( '<', $path, '>', $dest ) if ( $path ne $dest );
334                  } elsif ( -s $path < $min_compress_size ) {                  } elsif ( -s $path < $min_compress_size ) {
335                          warn "release $file -- uncompressed, too small [", -s $path, "]\n";                          warn "release $file [",-s $path,"] uncompressed, too small\n";
336                          file_copy( '<', $path, '>', $dest ) if ( $path ne $dest );                          file_copy( '<', $path, '>', $dest ) if ( $path ne $dest );
337                  } else {                  } else {
338                          warn "release $file $mode -- compressing\n";                          warn "release $file [",-s $path,"] compressing\n";
339    
340                            my $comp = $dest . '.gz';
341                            file_copy( '<', $path, '>:gzip', $comp );
342    
343                          file_copy( '<', $path, '>:gzip', $dest . '.gz' );                          my ( $size_path, $size_comp ) = ( -s $path, -s $comp );
344    
345                          # FIXME add timeout to remove uncompressed version?                          if ( $size_path <= $size_comp ) {
346                          # FIXME leave uncompressed file if smaller than compressed                                  warn ">>> $size_path <= $size_comp leaving uncompressed\n";
347                          unlink $path || warn "can't remove $path: $!";                                  unlink $comp || warn "can't reamove: $comp: $!";
348                            } else {
349                                    warn ">>> compressed $size_path -> $size_comp ",int(($size_comp * 100) / $size_path),"%\n";
350                                    # FIXME add timeout to remove uncompressed version?
351                                    unlink $path || warn "can't remove $path: $!";
352                            }
353                  }                  }
354          } else {          } else {
355                  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";
# Line 352  Fuse::main( Line 386  Fuse::main(
386          statfs  =>"main::x_statfs",          statfs  =>"main::x_statfs",
387          release =>"main::x_release",          release =>"main::x_release",
388  #       threaded=>1,  #       threaded=>1,
389  #       debug   => 1,          debug   => $fuse_debug,
390  );  );

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

  ViewVC Help
Powered by ViewVC 1.1.26