/[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 8 by dpavlin, Sun Jul 8 17:04:18 2007 UTC revision 13 by dpavlin, Mon Jul 9 11:12:48 2007 UTC
# Line 11  use PerlIO::gzip; Line 11  use PerlIO::gzip;
11  use File::Path;  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;
15    
16  my $mount = {  my $mount = {
17          from    => '/tmp/comp',          from    => '/tmp/comp',
# Line 102  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 $d_opt $d_path )\n";          warn "## file_copy( $s_opt $s_path [",-s $s_path,"] $d_opt $d_path [",-e $d_path ? -s $d_path : 'new',"])\n";
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;
110          while( read( $s, $buff, 65535 ) ) {          while( read( $s, $buff, 65535 ) ) {
111                  print $d $buff || confess "can't write into $d_path: $!";                  print $d $buff || confess "can't write into $d_path: $!";
112                  warn ">> ", length($buff), " bytes, offset ", tell($s), " -> ", tell($d), "\n" if $debug;                  warn ">> [", length($buff), "] offset ", tell($s), " -> ", tell($d), "\n" if $debug;
113          }          }
114          close($d) || warn "can't close $d_path: $!";          close($d) || warn "can't close $d_path: $!";
115          close($s) || warn "can't close $s_path: $!";          close($s) || warn "can't close $s_path: $!";
# Line 126  sub file_copy { Line 127  sub file_copy {
127  sub x_open {  sub x_open {
128          my ($file) = shift;          my ($file) = shift;
129          my ($mode) = shift;          my ($mode) = shift;
130    
131            if ( $file eq '/.debug' ) {
132                    my $path = $mount->{from} . '/.debug';
133                    open( my $debug, '>', $path ) || die "can't open $path: $!";
134                    my $dump = dump( $pending );
135                    print $debug "pending = $dump\n";
136                    close($debug);
137                    $pending->{'/.debug'}->{path} = $path;
138                    warn "## created dump $path $dump\n";
139                    return 0;
140            }
141    
142          $pending->{$file}->{open}++;          $pending->{$file}->{open}++;
143    
144          my $mode_desc = {          my $mode_desc = {
# Line 148  sub x_open { Line 161  sub x_open {
161                  file_copy( '<:gzip', $path, '>', $tmp );                  file_copy( '<:gzip', $path, '>', $tmp );
162                  $path = $tmp;                  $path = $tmp;
163          }          }
164          warn ">>> open abs path: $path ", -s $path, " bytes\n";          warn ">>> open abs path: $path [", -s $path, "]\n";
165          return -$! unless sysopen($fh , $path, $mode);          return -$! unless sysopen($fh , $path, $mode);
166            close($fh);
167    
         $pending->{$file}->{fh} = $fh;  
168          $pending->{$file}->{path} = $path;          $pending->{$file}->{path} = $path;
         $pending->{$file}->{mode} = {  
                 rdonly => $mode && O_RDONLY,  
                 rdwr => $mode && O_RDWR,  
                 append => $mode && O_APPEND,  
                 create => $mode && O_CREAT,  
         };  
169          return 0;          return 0;
170  }  }
171    
# Line 166  sub x_read { Line 173  sub x_read {
173          my ($file,$bufsize,$off) = @_;          my ($file,$bufsize,$off) = @_;
174          my ($rv) = -ENOSYS();          my ($rv) = -ENOSYS();
175          my $path = fixup( $file );          my $path = fixup( $file );
176    
177            confess "no pending file $file ", dump( $pending ) unless defined( $pending->{$file} );
178    
179          return -ENOENT() unless -e $path;          return -ENOENT() unless -e $path;
180          my ($fsize) = -s $path;  
181          my $fh = $pending->{$file}->{fh} || confess "no fh? ", dump( $pending );          my $fh = new IO::File;
182            return -ENOSYS() unless open($fh,$pending->{$file}->{path});
183    
184          if(seek($fh,$off,SEEK_SET)) {          if(seek($fh,$off,SEEK_SET)) {
185                  read($fh,$rv,$bufsize);                  read($fh,$rv,$bufsize);
186          }          }
187    
188          return $rv;          return $rv;
189  }  }
190    
191  sub x_write {  sub x_write {
192          my ($file,$buf,$off) = @_;          my ($file,$buf,$off) = @_;
193          $pending->{$file}->{write}++;          $pending->{$file}->{write}++;
194          my ($rv);          my $rv;
195          my $path = fixup($file);          my $path = fixup($file);
196    
197            confess "no pending file $file ", dump( $pending ) unless defined( $pending->{$file} );
198    
199          return -ENOENT() unless -e $path;          return -ENOENT() unless -e $path;
200          my ($fsize) = -s $path;  
201          my $fh = $pending->{$file}->{fh};          my $fh = new IO::File;
202          return -ENOSYS() unless $fh;          return -ENOSYS() unless open($fh,'+<',$pending->{$file}->{path});
203          if($rv = seek( $fh ,$off,SEEK_SET)) {          if($rv = seek( $fh ,$off,SEEK_SET)) {
204                  $rv = print( $fh $buf );                  $rv = print( $fh $buf );
205                    warn "## ", $pending->{$file}->{path}, " $off ",length( $buf ), "\n" if $debug;
206          }          }
207          $rv = -ENOSYS() unless $rv;          $rv = -ENOSYS() unless $rv;
208            close($fh);
209          return length($buf);          return length($buf);
210  }  }
211    
# Line 249  sub x_release { Line 267  sub x_release {
267          } elsif ( ! defined( $pending->{$file}->{write} ) ) {          } elsif ( ! defined( $pending->{$file}->{write} ) ) {
268                  warn "release $file, not written into\n";                  warn "release $file, not written into\n";
269          } elsif ( defined( $pending->{$file}->{open} ) && $pending->{$file}->{open} == 1 ) {          } elsif ( defined( $pending->{$file}->{open} ) && $pending->{$file}->{open} == 1 ) {
                 close( $pending->{$file}->{fh} ) || warn "can't close $file: $!";  
270                  my $path = $pending->{$file}->{path} || confess "no path for $file ? ", dump( $pending );                  my $path = $pending->{$file}->{path} || confess "no path for $file ? ", dump( $pending );
271                  my $dest = fixup( $file );                  my $dest = fixup( $file );
272    
# Line 264  sub x_release { Line 281  sub x_release {
281                          warn "release $file $mode -- uncompressed\n";                          warn "release $file $mode -- uncompressed\n";
282                          file_copy( '<', $path, '>', $dest ) if ( $path ne $dest );                          file_copy( '<', $path, '>', $dest ) if ( $path ne $dest );
283                  } elsif ( -s $path < $min_compress_size ) {                  } elsif ( -s $path < $min_compress_size ) {
284                          warn "release $file -- uncompressed, too small ", -s $path, " bytes\n";                          warn "release $file -- uncompressed, too small [", -s $path, "]\n";
285                          file_copy( '<', $path, '>', $dest ) if ( $path ne $dest );                          file_copy( '<', $path, '>', $dest ) if ( $path ne $dest );
286                  } else {                  } else {
287                          warn "release $file $mode -- compressing\n";                          warn "release $file $mode -- compressing\n";
# Line 277  sub x_release { Line 294  sub x_release {
294                  }                  }
295          } else {          } else {
296                  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";
                 $pending->{$file}->{open}--;  
                 return 0;  
297          }          }
298          delete( $pending->{$file} );          $pending->{$file}->{open}--;
299            if ( $pending->{$file}->{open} == 0 ) {
300                    warn "## cleanup pending $file [", -s fixup($file), "]\n" if $debug;
301                    delete( $pending->{$file} );
302            }
303          return 0;          return 0;
304  }  }
305    

Legend:
Removed from v.8  
changed lines
  Added in v.13

  ViewVC Help
Powered by ViewVC 1.1.26