/[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 14 by dpavlin, Mon Jul 9 13:04:25 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 = 1;  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 103  sub x_getdir { Line 103  sub x_getdir {
103    
104  sub file_copy {  sub file_copy {
105          my ( $s_opt, $s_path, $d_opt, $d_path ) = @_;          my ( $s_opt, $s_path, $d_opt, $d_path ) = @_;
106          warn "## file_copy( $s_opt $s_path [",-s $s_path,"] $d_opt $d_path [",-e $d_path ? -s $d_path : 'new',"])\n";          warn "## file_copy( $s_opt $s_path [",-s $s_path,"] $d_opt $d_path [",-e $d_path ? -s $d_path : 'new',"])\n" if $debug;
107          open(my $s, $s_opt, $s_path ) || confess "can't open $s_path: $!\npending = ", dump( $pending );          open(my $s, $s_opt, $s_path ) || confess "can't open $s_path: $!\npending = ", dump( $pending );
108          open(my $d, $d_opt, $d_path ) || confess "can't open $d_path: $!";          open(my $d, $d_opt, $d_path ) || confess "can't open $d_path: $!";
109          my $buff;          my $buff;
# Line 149  sub x_open { Line 149  sub x_open {
149                  trunc => $mode && O_TRUNC,                  trunc => $mode && O_TRUNC,
150          };          };
151          my $path = fixup($file);          my $path = fixup($file);
152          warn "# open( $file, $mode ) pending: ", $pending->{$file}->{open}, " mode $mode: ", dump( $mode_desc )," $path [", -s $path, "]\n";          warn "## open( $file, $mode ) pending: ", $pending->{$file}->{open}, " mode $mode: ", dump( $mode_desc )," $path [", -s $path, "]\n" if $debug;
153          my $fh;          my $fh;
154    
155          my $tmp = $mount->{tmp} . '/' . $file;          my $tmp = $mount->{tmp} . '/' . $file;
# Line 162  sub x_open { Line 162  sub x_open {
162                  file_copy( '<:gzip', $path, '>', $tmp );                  file_copy( '<:gzip', $path, '>', $tmp );
163                  $path = $tmp;                  $path = $tmp;
164          }          }
165          warn ">>> open abs path: $path [", -e $path ? -s $path : 'new' , "]\n";          warn "<<< open abs path: $path [", -e $path ? -s $path : 'new' , "]\n";
166          return -$! unless sysopen($fh , $path, $mode);          return -$! unless sysopen($fh , $path, $mode);
         warn ">>> after open [",-s $path, "]\n";  
167          close($fh);          close($fh);
168    
169          $pending->{$file}->{path} = $path;          $pending->{$file}->{path} = $path;
# Line 204  sub x_write { Line 203  sub x_write {
203          return -ENOSYS() unless open($fh,'+<',$pending->{$file}->{path});          return -ENOSYS() unless open($fh,'+<',$pending->{$file}->{path});
204          if($rv = seek( $fh ,$off,SEEK_SET)) {          if($rv = seek( $fh ,$off,SEEK_SET)) {
205                  $rv = print( $fh $buf );                  $rv = print( $fh $buf );
206                  warn "## ", $pending->{$file}->{path}, " $off ",length( $buf ), "\n" if $debug;                  warn "## write ", $pending->{$file}->{path}, " $off ",length( $buf ), "\n" if $debug;
207          }          }
208          $rv = -ENOSYS() unless $rv;          $rv = -ENOSYS() unless $rv;
209          close($fh);          close($fh);
# Line 219  sub x_unlink   { return unlink_all( shif Line 218  sub x_unlink   { return unlink_all( shif
218  sub x_symlink { return symlink(shift,fixup(shift)) ? 0 : -$!; }  sub x_symlink { return symlink(shift,fixup(shift)) ? 0 : -$!; }
219    
220  sub x_rename {  sub x_rename {
221          my ($old) = fixup(shift);          my ($old,$new) = @_;
222          my ($new) = fixup(shift);          my $old_path = fixup($old);
223          my ($err) = rename($old,$new) ? 0 : -ENOENT();          my $new_path = fixup($new);
224            $new_path .= '.gz' if ( $old_path =~ m/\.gz$/ && $new_path !~ m/\.gz$/ );
225    
226            my $err = rename($old_path,$new_path) ? 0 : -ENOENT();
227            warn "## rename( $old_path => $new_path ) = $err\n";
228    
229            my $tmp = $mount->{tmp} . '/' . $old;
230            if ( -e $tmp ) {
231                    my $new_tmp = $mount->{tmp} . '/' . $new;
232                    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 255  sub x_truncate { Line 275  sub x_truncate {
275                  rename $path, $no_gz || confess "can't rename $path -> $no_gz: $!";                  rename $path, $no_gz || confess "can't rename $path -> $no_gz: $!";
276          }          }
277          warn "## truncate( $file $size ) $path [", -s $path, "]\n";          warn "## truncate( $file $size ) $path [", -s $path, "]\n";
278            $pending->{$file}->{write}++;
279          return $rv;          return $rv;
280  }  }
281  sub x_utime { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; }  sub x_utime { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; }
# Line 291  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.14  
changed lines
  Added in v.20

  ViewVC Help
Powered by ViewVC 1.1.26