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 |
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); |
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 |
|
|
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 |
|
|
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 |
|
|
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} )) { |
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; |
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 |
|
|
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; |