/[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 24 by dpavlin, Mon Jul 9 21:57:11 2007 UTC revision 26 by dpavlin, Mon Jul 9 23:28:58 2007 UTC
# Line 76  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 180  sub x_open { Line 166  sub x_open {
166                  $pending->{$file}->{path} = $path;                  $pending->{$file}->{path} = $path;
167                  return 0;                  return 0;
168          } else {          } else {
169                  warn "ERROR: can't open $path : $!";                  warn "ERROR: can't open $path -- $!";
170                  return -$!;                  return -$!;
171          }          }
172    
# Line 207  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          $pending->{$file}->{write}++;  
197          my $rv;          my $rv;
198          my $path = fixup($file);          my $path = fixup($file);
199    
# Line 215  sub x_write { Line 201  sub x_write {
201    
202          return -ENOENT() unless -e $path;          return -ENOENT() unless -e $path;
203    
204            $path = $pending->{$file}->{path} || confess "no path for $file in ", dump( $pending );
205            confess "write into non-existant $path for $file: $!" unless -e $path;
206    
207          my $fh = new IO::File;          my $fh = new IO::File;
208          return -ENOSYS() unless open($fh,'+<',$pending->{$file}->{path});          return -ENOSYS() unless open($fh,'+<',$path);
209          if($rv = seek( $fh ,$off,SEEK_SET)) {          if($rv = seek( $fh ,$off,SEEK_SET)) {
210                  $rv = print( $fh $buf );                  $rv = print( $fh $buf );
211                  warn "## write ", $pending->{$file}->{path}, " $off ",length( $buf ), "\n" if $debug;                  warn "## write $path offset $off [",length( $buf ), "]\n" if $debug;
212                    $pending->{$file}->{write}++;
213          }          }
214          $rv = -ENOSYS() unless $rv;          $rv = -ENOSYS() unless $rv;
215          close($fh);          close($fh) || warn "can't close $path: $!";
216          return length($buf);          return length($buf);
217  }  }
218    
219  sub err { return (-shift || -$!) }  sub err { return (-shift || -$!) }
220    
221  sub x_readlink { return readlink(fixup(shift));         }  sub x_readlink { return readlink(fixup(shift));         }
222  sub x_unlink   { return unlink_all( shift ) ? 0 : -$! }  sub x_unlink   {
223            my $file = shift;
224            my $path = fixup( $file );
225    
226            if ( $file =~ m#\Q/.fuse_hidden\E# ) {
227                    return unlink $path ? 0 : -$1;
228            }
229    
230            warn "# unlink( $file )\n";
231    
232            unlink $path || return 0;
233    
234            my $tmp = $mount->{tmp} . '/' . $file;
235            unlink $tmp if ( -e $tmp );
236    
237            delete( $pending->{$file} );
238            return 0;
239    }
240    
241  sub x_symlink { return symlink(shift,fixup(shift)) ? 0 : -$!; }  sub x_symlink { return symlink(shift,fixup(shift)) ? 0 : -$!; }
242    
# Line 244  sub x_rename { Line 251  sub x_rename {
251    
252          my $tmp = $mount->{tmp} . '/' . $old;          my $tmp = $mount->{tmp} . '/' . $old;
253          if ( -e $tmp ) {          if ( -e $tmp ) {
254                  my $new_tmp = $mount->{tmp} . '/' . $new;                  if ( $new =~ m#\Q/.fuse_hidden\E# ) {
255                  rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!";                          unlink $tmp || confess "can't unlink $tmp for $new\n";
256                    } else {
257                            my $new_tmp = $mount->{tmp} . '/' . $new;
258                            rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!";
259                    }
260          }          }
261    
262          if (defined( $pending->{$old} )) {          if (defined( $pending->{$old} )) {
# Line 254  sub x_rename { Line 265  sub x_rename {
265                  my $path = $pending->{$old}->{path};                  my $path = $pending->{$old}->{path};
266                  $path =~ s/\Q$old\E/$new/;                  $path =~ s/\Q$old\E/$new/;
267                  $pending->{$new}->{path} = $path;                  $pending->{$new}->{path} = $path;
                 $pending->{$old}->{path} = $path;  
268    
269                  #delete( $pending->{$old} );                  delete( $pending->{$old} );
270                    warn "## tweaking pending to ", dump( $pending ) if $debug;
271          }          }
272    
273          return $err;          return $err;
# Line 264  sub x_rename { Line 275  sub x_rename {
275  sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! }  sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! }
276    
277  sub x_chown {  sub x_chown {
278          my ($path) = fixup(shift);          my ($file,$uid,$gid) = @_;
279            my $path = fixup($file);
280          print "nonexistent $path\n" unless -e $path;          print "nonexistent $path\n" unless -e $path;
         my ($uid,$gid) = @_;  
281          # perl's chown() does not chown symlinks, it chowns the symlink's          # perl's chown() does not chown symlinks, it chowns the symlink's
282          # target.  it fails when the link's target doesn't exist, because          # target.  it fails when the link's target doesn't exist, because
283          # the stat64() syscall fails.          # the stat64() syscall fails.
284          # this causes error messages when unpacking symlinks in tarballs.          # this causes error messages when unpacking symlinks in tarballs.
285          my ($err) = syscall(&SYS_lchown,$path,$uid,$gid,$path) ? -$! : 0;          my ($err) = syscall(&SYS_lchown,$path,$uid,$gid,$path) ? -$! : 0;
286    
287            my $tmp = $mount->{tmp} . '/' . $file;
288            syscall(&SYS_lchown,$file,$uid,$gid,$path) if -e $tmp;
289    
290          return $err;          return $err;
291  }  }
292    
# Line 312  sub x_mknod { Line 327  sub x_mknod {
327    
328  sub x_release {  sub x_release {
329          my ( $file, $mode ) = @_;          my ( $file, $mode ) = @_;
330    
331            if ( $file =~ m#\Q/.fuse_hidden\E# ) {
332                    warn "release internal $file\n" if $debug;
333                    delete( $pending->{$file} );
334                    return 0;
335            }
336    
337          if ( ! defined( $pending->{$file} ) ) {          if ( ! defined( $pending->{$file} ) ) {
338                  warn "release $file, NO PENDING DATA\n";                  warn "release $file, NO PENDING DATA\n";
339                  return 0;                  return 0;

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

  ViewVC Help
Powered by ViewVC 1.1.26