/[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 21 by dpavlin, Mon Jul 9 17:35:26 2007 UTC revision 25 by dpavlin, Mon Jul 9 22:44:20 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 = shift @ARGV;  
   
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 69  sub gzip_original_size { Line 76  sub gzip_original_size {
76          return unpack("L", $buff);          return unpack("L", $buff);
77  }  }
78    
 sub unlink_all {  
         my $file = shift;  
         warn "# unlink_all( $file )\n";  
   
         my $path = fixup( $file );  
         unlink $path || return 0;  
   
         my $tmp = $mount->{tmp} . '/' . $file;  
         unlink $tmp if ( -e $tmp );  
   
         delete( $pending->{$file} );  
         return 1;  
 }  
   
79  sub x_getattr {  sub x_getattr {
80          my ($file) = fixup(shift);          my ($file) = fixup(shift);
81          my (@list) = lstat($file);          my (@list) = lstat($file);
# Line 159  sub x_open { Line 152  sub x_open {
152                  my $dest_path = $tmp;                  my $dest_path = $tmp;
153                  $dest_path =~ s!/[^/]+$!!;      #!vim-fix                  $dest_path =~ s!/[^/]+$!!;      #!vim-fix
154                  mkpath $dest_path unless -e $dest_path;                  mkpath $dest_path unless -e $dest_path;
155                  file_copy( '<:gzip', $path, '>', $tmp );                  if ( -s $path ) {
156                            file_copy( '<:gzip', $path, '>', $tmp )
157                    } else {
158                            warn "ERROR: filesystem corruption, $path is zero size\n";
159                    }
160                  $path = $tmp;                  $path = $tmp;
161          }          }
162    
# Line 196  sub x_read { Line 193  sub x_read {
193    
194  sub x_write {  sub x_write {
195          my ($file,$buf,$off) = @_;          my ($file,$buf,$off) = @_;
196    
197          $pending->{$file}->{write}++;          $pending->{$file}->{write}++;
198          my $rv;          my $rv;
199          my $path = fixup($file);          my $path = fixup($file);
# Line 218  sub x_write { Line 216  sub x_write {
216  sub err { return (-shift || -$!) }  sub err { return (-shift || -$!) }
217    
218  sub x_readlink { return readlink(fixup(shift));         }  sub x_readlink { return readlink(fixup(shift));         }
219  sub x_unlink   { return unlink_all( shift ) ? 0 : -$! }  sub x_unlink   {
220            my $file = shift;
221            my $path = fixup( $file );
222    
223            if ( $file =~ m#\Q/.fuse_hidden\E# ) {
224                    return unlink $path ? 0 : -$1;
225            }
226    
227            warn "# unlink( $file )\n";
228    
229            unlink $path || return 0;
230    
231            my $tmp = $mount->{tmp} . '/' . $file;
232            unlink $tmp if ( -e $tmp );
233    
234            delete( $pending->{$file} );
235            return 0;
236    }
237    
238  sub x_symlink { return symlink(shift,fixup(shift)) ? 0 : -$!; }  sub x_symlink { return symlink(shift,fixup(shift)) ? 0 : -$!; }
239    
# Line 233  sub x_rename { Line 248  sub x_rename {
248    
249          my $tmp = $mount->{tmp} . '/' . $old;          my $tmp = $mount->{tmp} . '/' . $old;
250          if ( -e $tmp ) {          if ( -e $tmp ) {
251                  my $new_tmp = $mount->{tmp} . '/' . $new;                  if ( $new =~ m#\Q/.fuse_hidden\E# ) {
252                  rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!";                          unlink $tmp || confess "can't unlink $tmp for $new\n";
253                    } else {
254                            my $new_tmp = $mount->{tmp} . '/' . $new;
255                            rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!";
256                    }
257          }          }
258    
259          if (defined( $pending->{$old} )) {          if (defined( $pending->{$old} )) {
# Line 245  sub x_rename { Line 264  sub x_rename {
264                  $pending->{$new}->{path} = $path;                  $pending->{$new}->{path} = $path;
265    
266                  delete( $pending->{$old} );                  delete( $pending->{$old} );
267                    warn "## tweaking pending to ", dump( $pending ) if $debug;
268          }          }
269    
270          return $err;          return $err;
# Line 300  sub x_mknod { Line 320  sub x_mknod {
320    
321  sub x_release {  sub x_release {
322          my ( $file, $mode ) = @_;          my ( $file, $mode ) = @_;
323    
324            if ( $file =~ m#\Q/.fuse_hidden\E# ) {
325                    warn "release internal $file\n" if $debug;
326                    delete( $pending->{$file} );
327                    return 0;
328            }
329    
330          if ( ! defined( $pending->{$file} ) ) {          if ( ! defined( $pending->{$file} ) ) {
331                  warn "release $file, NO PENDING DATA\n";                  warn "release $file, NO PENDING DATA\n";
332                  return 0;                  return 0;
# Line 374  Fuse::main( Line 401  Fuse::main(
401          statfs  =>"main::x_statfs",          statfs  =>"main::x_statfs",
402          release =>"main::x_release",          release =>"main::x_release",
403  #       threaded=>1,  #       threaded=>1,
404  #       debug   => 1,          debug   => $fuse_debug,
405  );  );

Legend:
Removed from v.21  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.26