4 |
use threads::shared; |
use threads::shared; |
5 |
|
|
6 |
use Fuse; |
use Fuse; |
|
use IO::File; |
|
7 |
use POSIX qw(ENOENT ENOSYS EEXIST EPERM O_RDONLY O_RDWR O_APPEND O_CREAT); |
use POSIX qw(ENOENT ENOSYS EEXIST EPERM O_RDONLY O_RDWR O_APPEND O_CREAT); |
8 |
use Fcntl qw(S_ISBLK S_ISCHR S_ISFIFO SEEK_SET); |
use Fcntl qw(S_ISBLK S_ISCHR S_ISFIFO SEEK_SET); |
9 |
require 'syscall.ph'; # for SYS_mknod and SYS_lchown |
require 'syscall.ph'; # for SYS_mknod and SYS_lchown |
10 |
use PerlIO::gzip; |
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 cluck/; |
14 |
|
use IO::File; |
15 |
|
use Getopt::Long; |
16 |
|
|
17 |
|
my $debug = 0; |
18 |
|
my $fuse_debug = 0; |
19 |
|
my $stats = 1; |
20 |
|
|
21 |
|
GetOptions( |
22 |
|
'debug+' => \$debug, |
23 |
|
'fuse-debug+' => \$fuse_debug, |
24 |
|
'stats!' => \$stats, |
25 |
|
); |
26 |
|
|
27 |
my $mount = { |
my $mount = { |
28 |
from => '/tmp/comp', |
from => shift @ARGV || '/tmp/comp', |
29 |
to => '/tmp/no-comp', |
to => shift @ARGV || '/tmp/no-comp', |
30 |
tmp => '/dev/shm/comp', |
tmp => shift @ARGV || '/dev/shm/comp', |
31 |
}; |
}; |
32 |
|
|
33 |
my $debug = 1; |
warn "mount $mount->{from} to $mount->{to} using $mount->{tmp} as cache\n"; |
34 |
|
|
35 |
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/gz|gz%|\.(?:sw[a-z]|gif|png|jpeg|jpg|avi|rar|zip|bz2|tgz|avi|mpeg|mpg|tmp|temp)$/i; |
36 |
|
|
37 |
# don't compress files smaller than this |
# don't compress files smaller than this |
38 |
my $min_compress_size = 256; |
my $min_compress_size = 512; |
39 |
|
|
40 |
foreach my $dir ( keys %$mount ) { |
foreach my $dir ( keys %$mount ) { |
41 |
if ( ! -e $mount->{$dir} ) { |
if ( ! -e $mount->{$dir} ) { |
46 |
|
|
47 |
my $pending; |
my $pending; |
48 |
|
|
49 |
|
sub real_name { |
50 |
|
my ( $dir, $name ) = @_; |
51 |
|
if ( -e "$dir/${name}.gz" ) { |
52 |
|
cluck "ASSERT: unexpected $dir/$name exists" if -e "$dir/$name"; |
53 |
|
return "${name}.gz"; |
54 |
|
} |
55 |
|
if ( $name =~ m/\.gz$/ ) { |
56 |
|
return $name . '%'; # protect (mingle) compressed files |
57 |
|
} else { |
58 |
|
return $name; |
59 |
|
} |
60 |
|
} |
61 |
|
|
62 |
sub fixup { |
sub fixup { |
63 |
my ( $path ) = @_; |
my ( $path ) = @_; |
64 |
my $full = $mount->{from} . '/' . $path; |
return $mount->{from} . '/' . real_name( $mount->{from}, $path ); |
|
if ( -e $full . '.gz' ) { |
|
|
return $full . '.gz'; |
|
|
} |
|
|
return $full; |
|
65 |
} |
} |
66 |
|
|
67 |
sub original_name { |
sub original_name { |
68 |
my $p = shift; |
my $p = shift; |
69 |
$p =~ s/\.gz$//; |
$p =~ s/\.gz$//; |
70 |
|
$p =~ s/\.gz%$/.gz/; # demungle compressed .gz files |
71 |
return $p; |
return $p; |
72 |
}; |
}; |
73 |
|
|
90 |
return unpack("L", $buff); |
return unpack("L", $buff); |
91 |
} |
} |
92 |
|
|
|
sub unlink_all { |
|
|
my $file = shift; |
|
|
foreach my $dir ( keys %$mount ) { |
|
|
my $path = $mount->{$dir} . '/' . $file; |
|
|
|
|
|
map { |
|
|
my $path = $_; |
|
|
if ( -e $path ) { |
|
|
if ( unlink $path ) { |
|
|
warn "## unlink $path\n" if $debug; |
|
|
} else { |
|
|
warn "can't unlink $path: $!\n"; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
} [ $path, $path . '.gz' ]; |
|
|
} |
|
|
delete( $pending->{$file} ); |
|
|
return 1; |
|
|
} |
|
|
|
|
93 |
sub x_getattr { |
sub x_getattr { |
94 |
my ($file) = fixup(shift); |
my ($file) = fixup(shift); |
95 |
my (@list) = lstat($file); |
my (@list) = lstat($file); |
110 |
|
|
111 |
sub file_copy { |
sub file_copy { |
112 |
my ( $s_opt, $s_path, $d_opt, $d_path ) = @_; |
my ( $s_opt, $s_path, $d_opt, $d_path ) = @_; |
113 |
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" if $debug; |
114 |
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 ); |
115 |
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: $!"; |
116 |
my $buff; |
my $buff; |
117 |
while( read( $s, $buff, 65535 ) ) { |
while( read( $s, $buff, 65535 ) ) { |
118 |
print $d $buff || confess "can't write into $d_path: $!"; |
print $d $buff || confess "can't write into $d_path: $!"; |
119 |
warn ">> ", length($buff), " bytes, offset ", tell($s), " -> ", tell($d), "\n" if $debug; |
warn ">> [", length($buff), "] offset ", tell($s), " -> ", tell($d), "\n" if $debug; |
120 |
} |
} |
121 |
close($d) || warn "can't close $d_path: $!"; |
close($d) || warn "can't close $d_path: $!"; |
122 |
close($s) || warn "can't close $s_path: $!"; |
close($s) || warn "can't close $s_path: $!"; |
126 |
chmod $mode, $d_path || warn "chmod( $mode $d_path ) failed: $!\n"; |
chmod $mode, $d_path || warn "chmod( $mode $d_path ) failed: $!\n"; |
127 |
chown $uid,$gid,$d_path || warn "chown( $uid $gid $d_path ) failed: $!\n"; |
chown $uid,$gid,$d_path || warn "chown( $uid $gid $d_path ) failed: $!\n"; |
128 |
utime $atime,$mtime,$d_path || warn "utime( $atime $mtime $d_path ) failed: $!\n"; |
utime $atime,$mtime,$d_path || warn "utime( $atime $mtime $d_path ) failed: $!\n"; |
129 |
|
|
130 |
|
undef $d; |
131 |
|
undef $s; |
132 |
} |
} |
133 |
|
|
134 |
sub x_open { |
sub tmp_path { |
135 |
my ($file) = shift; |
my $file = shift; |
136 |
my ($mode) = shift; |
|
137 |
$pending->{$file}->{open}++; |
my $path = fixup( $file ); |
138 |
warn "# open( $file, $mode ) pending: ", $pending->{$file}->{open}, "\n"; |
|
139 |
my $fh; |
my $op = 'UNKNOWN'; |
140 |
if ( $pending->{$file}->{open} == 1 ) { |
|
141 |
my $path = fixup($file); |
if (defined( $pending->{$file} )) { |
142 |
|
$path = $pending->{$file}->{path} || confess "no path for $file in ",dump( $pending ); |
143 |
|
$op = 'opened'; |
144 |
|
} else { |
145 |
my $tmp = $mount->{tmp} . '/' . $file; |
my $tmp = $mount->{tmp} . '/' . $file; |
|
warn ">>> open abs path: $path\n"; |
|
146 |
if ( -e $tmp ) { |
if ( -e $tmp ) { |
147 |
$path = $tmp; |
$path = $tmp; |
148 |
|
$op = 'existing'; |
149 |
} elsif ( $path =~ m/\.gz$/ ) { |
} elsif ( $path =~ m/\.gz$/ ) { |
150 |
my $dest_path = $tmp; |
my $dest_path = $tmp; |
151 |
$dest_path =~ s!/[^/]+$!!; #!vim-fix |
$dest_path =~ s!/[^/]+$!!; #!vim-fix |
152 |
mkpath $dest_path unless -e $dest_path; |
mkpath $dest_path unless -e $dest_path; |
153 |
file_copy( '<:gzip', $path, '>', $tmp ); |
if ( -s $path ) { |
154 |
|
file_copy( '<:gzip', $path, '>', $tmp ) |
155 |
|
} else { |
156 |
|
confess "ASSERT: filesystem corruption, $path is zero size in ",dump( $pending ); |
157 |
|
} |
158 |
$path = $tmp; |
$path = $tmp; |
159 |
|
$op = 'created'; |
160 |
} |
} |
161 |
return -$! unless sysopen($fh , $path, $mode); |
confess "ASSERT: path shouldn't exist for $file in ", dump( $pending ) if defined( $pending->{$file}->{path} ); |
162 |
$pending->{$file}->{fh} = $fh; |
confess "ASSERT: open shouldn't exist for $file in ", dump( $pending ) if defined( $pending->{$file}->{open} ); |
163 |
$pending->{$file}->{path} = $path; |
$pending->{$file}->{path} = $path; |
164 |
} elsif ( ! defined( $pending->{$file}->{fh} ) ) { |
$pending->{$file}->{open} = 0; # not really opened, just uncompressed |
165 |
confess "can't find fh for $file ", dump($pending); |
warn "## tmp_file( $file ) $op $path [", -s $path, "]\n" if $debug; |
166 |
|
} |
167 |
|
return $path; |
168 |
|
} |
169 |
|
|
170 |
|
sub compress_file2path { |
171 |
|
my ( $file, $path ) = @_; |
172 |
|
|
173 |
|
my $dest = fixup( $file ); |
174 |
|
|
175 |
|
if ( defined($pending->{$file}) ) { |
176 |
|
my $pending_path = $pending->{$file}->{path} || confess "no path for $file in ",dump( $pending ); |
177 |
|
|
178 |
|
if ( $pending->{$file}->{open} > 1 ) { |
179 |
|
warn "$file used ", $pending->{$file}->{open}, " times, delaying compression\n"; |
180 |
|
return; |
181 |
|
} elsif ( ! $path ) { |
182 |
|
$path = $pending_path; |
183 |
|
} elsif ( $pending_path ne $path ) { |
184 |
|
confess "ASSERT: compressing into $path instead of $pending_path"; |
185 |
|
} |
186 |
|
} |
187 |
|
|
188 |
|
confess "need path" unless $path; |
189 |
|
|
190 |
|
# cleanup old compressed copy |
191 |
|
if ( $dest =~ /\.gz$/ ) { |
192 |
|
warn "## remove old $dest\n"; |
193 |
|
unlink $dest || confess "can't remove $dest: $!"; |
194 |
|
$dest =~ s/\.gz$//; |
195 |
|
confess "ASSERT: uncompressed $dest shouldn't exist!" if -e $dest; |
196 |
|
} |
197 |
|
|
198 |
|
if ( $path =~ $skip_extensions_regex ) { |
199 |
|
warn "$path [",-s $path,"] skipped compression\n"; |
200 |
|
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
201 |
|
} elsif ( -s $path < $min_compress_size ) { |
202 |
|
warn "$path [",-s $path,"] uncompressed, too small\n"; |
203 |
|
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
204 |
|
} else { |
205 |
|
warn "$path [",-s $path,"] compressing\n"; |
206 |
|
|
207 |
|
my $comp = $dest . '.gz'; |
208 |
|
file_copy( '<', $path, '>:gzip', $comp ); |
209 |
|
|
210 |
|
my ( $size_path, $size_comp ) = ( -s $path, -s $comp ); |
211 |
|
|
212 |
|
if ( $size_path <= $size_comp ) { |
213 |
|
warn ">>> $size_path <= $size_comp leaving uncompressed $dest\n"; |
214 |
|
unlink $comp || confess "can't remove: $comp: $!"; |
215 |
|
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
216 |
|
} else { |
217 |
|
warn ">>> compressed $size_path -> $size_comp ",int(($size_comp * 100) / $size_path),"% $comp\n"; |
218 |
|
|
219 |
|
# FIXME add timeout to remove uncompressed version? |
220 |
|
unlink $path || confess "can't remove $path: $!"; |
221 |
|
|
222 |
|
if ( -e $dest ) { |
223 |
|
warn "## cleanup uncompressed $dest\n" if $debug; |
224 |
|
unlink $dest || confess "can't remove $dest: $!"; |
225 |
|
} |
226 |
|
} |
227 |
|
|
228 |
|
} |
229 |
|
} |
230 |
|
|
231 |
|
sub x_open { |
232 |
|
my ($file) = shift; |
233 |
|
my ($mode) = shift; |
234 |
|
|
235 |
|
if ( $file eq '/.debug' ) { |
236 |
|
my $path = $mount->{from} . '/.debug'; |
237 |
|
open( my $debug, '>', $path ) || die "can't open $path: $!"; |
238 |
|
my $dump = dump( $pending ); |
239 |
|
print $debug "pending = $dump\n"; |
240 |
|
close($debug); |
241 |
|
$pending->{'/.debug'}->{path} = $path; |
242 |
|
warn "## created dump $path $dump\n"; |
243 |
|
return 0; |
244 |
|
} |
245 |
|
|
246 |
|
my $mode_desc = { |
247 |
|
rdonly => $mode && O_RDONLY, |
248 |
|
rdwr => $mode && O_RDWR, |
249 |
|
append => $mode && O_APPEND, |
250 |
|
create => $mode && O_CREAT, |
251 |
|
trunc => $mode && O_TRUNC, |
252 |
}; |
}; |
253 |
return 0; |
|
254 |
|
my $path = tmp_path( $file ); |
255 |
|
|
256 |
|
warn "## open( $file, $mode ) pending: ", $pending->{$file}->{open}, " mode $mode: ", dump( $mode_desc )," $path [", -s $path, "]\n" if $debug; |
257 |
|
|
258 |
|
my $fh; |
259 |
|
my $rv = 0; |
260 |
|
|
261 |
|
if ( ! -w $path ) { |
262 |
|
my $old_mode = (stat $path)[2]; |
263 |
|
my $new_mode = $old_mode | 0600; |
264 |
|
chmod $new_mode, $path || confess "can't chmod $new_mode $path"; |
265 |
|
warn "### modify mode $old_mode -> $new_mode for $path\n"; |
266 |
|
$pending->{$file}->{mode} = $old_mode; |
267 |
|
} |
268 |
|
|
269 |
|
if ( sysopen($fh , $path, $mode) ) { |
270 |
|
close($fh) || confess "can't close $path: $!"; |
271 |
|
warn "<<< sysopen $path [", -e $path ? -s $path : 'new' , "]\n"; |
272 |
|
$pending->{$file}->{open}++; |
273 |
|
} else { |
274 |
|
warn "ERROR: can't open $path -- $!"; |
275 |
|
$rv = -$!; |
276 |
|
} |
277 |
|
|
278 |
|
return $rv; |
279 |
|
|
280 |
} |
} |
281 |
|
|
282 |
sub x_read { |
sub x_read { |
283 |
my ($file,$bufsize,$off) = @_; |
my ($file,$bufsize,$off) = @_; |
284 |
my ($rv) = -ENOSYS(); |
my ($rv) = -ENOSYS(); |
285 |
my $path = fixup( $file ); |
my $path = fixup( $file ); |
286 |
|
|
287 |
|
confess "no pending file $file ", dump( $pending ) unless defined( $pending->{$file} ); |
288 |
|
|
289 |
return -ENOENT() unless -e $path; |
return -ENOENT() unless -e $path; |
290 |
my ($fsize) = -s $path; |
|
291 |
my $fh = $pending->{$file}->{fh} || confess "no fh? ", dump( $pending ); |
my $fh = new IO::File; |
292 |
|
return -ENOSYS() unless open($fh,$pending->{$file}->{path}); |
293 |
|
|
294 |
if(seek($fh,$off,SEEK_SET)) { |
if(seek($fh,$off,SEEK_SET)) { |
295 |
read($fh,$rv,$bufsize); |
read($fh,$rv,$bufsize); |
296 |
|
$pending->{$file}->{read} += length($rv) if $stats; |
297 |
} |
} |
298 |
|
|
299 |
return $rv; |
return $rv; |
300 |
} |
} |
301 |
|
|
302 |
sub x_write { |
sub x_write { |
303 |
my ($file,$buf,$off) = @_; |
my ($file,$buf,$off) = @_; |
304 |
$pending->{$file}->{write}++; |
|
305 |
my ($rv); |
my $rv; |
306 |
my $path = fixup($file); |
my $path = fixup($file); |
307 |
|
|
308 |
|
confess "no pending file $file ", dump( $pending ) unless defined( $pending->{$file} ); |
309 |
|
|
310 |
return -ENOENT() unless -e $path; |
return -ENOENT() unless -e $path; |
311 |
my ($fsize) = -s $path; |
|
312 |
my $fh = $pending->{$file}->{fh}; |
$path = $pending->{$file}->{path} || confess "no path for $file in ", dump( $pending ); |
313 |
return -ENOSYS() unless $fh; |
confess "write into non-existant $path for $file" unless -e $path; |
314 |
|
|
315 |
|
my $fh = new IO::File; |
316 |
|
return -ENOSYS() unless open($fh,'+<',$path); |
317 |
if($rv = seek( $fh ,$off,SEEK_SET)) { |
if($rv = seek( $fh ,$off,SEEK_SET)) { |
318 |
$rv = print( $fh $buf ); |
$rv = print( $fh $buf ); |
319 |
|
my $size = length($buf); |
320 |
|
warn "## write $path offset $off [$size]\n" if $debug; |
321 |
|
$pending->{$file}->{write} += $size; |
322 |
} |
} |
323 |
$rv = -ENOSYS() unless $rv; |
$rv = -ENOSYS() unless $rv; |
324 |
|
close($fh) || warn "can't close $path: $!"; |
325 |
return length($buf); |
return length($buf); |
326 |
} |
} |
327 |
|
|
328 |
sub err { return (-shift || -$!) } |
sub err { return (-shift || -$!) } |
329 |
|
|
330 |
sub x_readlink { return readlink(fixup(shift)); } |
sub x_readlink { return readlink(fixup(shift)); } |
331 |
sub x_unlink { return unlink_all( shift ) ? 0 : -$! } |
|
332 |
|
sub x_unlink { |
333 |
|
my $file = shift; |
334 |
|
my $path = fixup( $file ); |
335 |
|
|
336 |
|
if ( $file =~ m#\Q/.fuse_hidden\E# ) { |
337 |
|
return unlink $path ? 0 : -$1; |
338 |
|
} |
339 |
|
|
340 |
|
warn "# unlink( $file )\n"; |
341 |
|
|
342 |
|
unlink $path || return 0; |
343 |
|
|
344 |
|
my $tmp = $mount->{tmp} . '/' . $file; |
345 |
|
unlink $tmp if ( -e $tmp ); |
346 |
|
|
347 |
|
delete( $pending->{$file} ); |
348 |
|
return 0; |
349 |
|
} |
350 |
|
|
351 |
|
sub x_symlink { |
352 |
|
my ($from,$to) = @_; |
353 |
|
|
354 |
|
my $from_path = $from; #fixup( $from ); |
355 |
|
my $to_path = fixup( $to ); |
356 |
|
|
357 |
|
my $rv = symlink( $from_path, $to_path ) ? 0 : -$!; |
358 |
|
warn "# symlink( $from_path -> $to_path ) = $rv\n" if $debug; |
359 |
|
|
360 |
|
my $tmp = $mount->{tmp} . '/' . $from; |
361 |
|
my $tmp_to = $mount->{tmp} . '/' . $to; |
362 |
|
if ( $rv == 0 && -e $tmp_to ) { |
363 |
|
symlink( $tmp, $tmp_to ) || confess "can't symlink $tmp -> $tmp_to: $!"; |
364 |
|
} |
365 |
|
return $rv; |
366 |
|
} |
367 |
|
|
368 |
|
sub x_link { |
369 |
|
my ($from,$to) = @_; |
370 |
|
|
371 |
|
my $from_path = fixup($from); |
372 |
|
my $to_path = fixup($to); |
373 |
|
$to_path .= '.gz' if ( $from_path =~ m/\.gz$/ && $to_path !~ m/\.gz$/ ); |
374 |
|
|
375 |
sub x_symlink { return symlink(shift,fixup(shift)) ? 0 : -$!; } |
my $rv = link( $from_path, $to_path ) ? 0 : -$!; |
376 |
|
|
377 |
|
warn "# link( $from_path -> $to_path ) = $rv\n" if $debug; |
378 |
|
|
379 |
|
return $rv; |
380 |
|
} |
381 |
|
|
382 |
sub x_rename { |
sub x_rename { |
383 |
my ($old) = fixup(shift); |
my ($old,$new) = @_; |
384 |
my ($new) = fixup(shift); |
my $old_path = fixup($old); |
385 |
my ($err) = rename($old,$new) ? 0 : -ENOENT(); |
my $new_path = fixup($new); |
386 |
|
$new_path .= '.gz' if ( $old_path =~ m/\.gz$/ && $new_path !~ m/\.gz$/ ); |
387 |
|
|
388 |
|
my $err = rename($old_path,$new_path) ? 0 : -ENOENT(); |
389 |
|
warn "## rename( $old_path => $new_path ) = $err\n"; |
390 |
|
|
391 |
|
my $tmp = $mount->{tmp} . '/' . $old; |
392 |
|
if ( -e $tmp ) { |
393 |
|
if ( $new =~ m#\Q/.fuse_hidden\E# ) { |
394 |
|
unlink $tmp || confess "can't unlink $tmp for $new"; |
395 |
|
} else { |
396 |
|
my $new_tmp = $mount->{tmp} . '/' . $new; |
397 |
|
rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!"; |
398 |
|
} |
399 |
|
} |
400 |
|
|
401 |
|
if (defined( $pending->{$old} )) { |
402 |
|
$pending->{$new} = $pending->{$old}; |
403 |
|
|
404 |
|
my $path = $pending->{$old}->{path}; |
405 |
|
$path =~ s/\Q$old\E/$new/; |
406 |
|
$pending->{$new}->{path} = $path; |
407 |
|
|
408 |
|
delete( $pending->{$old} ); |
409 |
|
warn "## tweaking pending to ", dump( $pending ) if $debug; |
410 |
|
} |
411 |
|
|
412 |
return $err; |
return $err; |
413 |
} |
} |
|
sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! } |
|
414 |
|
|
415 |
sub x_chown { |
sub x_chown { |
416 |
my ($path) = fixup(shift); |
my ($file,$uid,$gid) = @_; |
417 |
|
my $path = fixup($file); |
418 |
print "nonexistent $path\n" unless -e $path; |
print "nonexistent $path\n" unless -e $path; |
|
my ($uid,$gid) = @_; |
|
419 |
# perl's chown() does not chown symlinks, it chowns the symlink's |
# perl's chown() does not chown symlinks, it chowns the symlink's |
420 |
# target. it fails when the link's target doesn't exist, because |
# target. it fails when the link's target doesn't exist, because |
421 |
# the stat64() syscall fails. |
# the stat64() syscall fails. |
422 |
# this causes error messages when unpacking symlinks in tarballs. |
# this causes error messages when unpacking symlinks in tarballs. |
423 |
my ($err) = syscall(&SYS_lchown,$path,$uid,$gid,$path) ? -$! : 0; |
my ($err) = syscall(&SYS_lchown,$path,$uid,$gid,$path) ? -$! : 0; |
424 |
|
|
425 |
|
my $tmp = $mount->{tmp} . '/' . $file; |
426 |
|
syscall(&SYS_lchown,$file,$uid,$gid,$path) if -e $tmp; |
427 |
|
|
428 |
return $err; |
return $err; |
429 |
} |
} |
430 |
|
|
435 |
return $err; |
return $err; |
436 |
} |
} |
437 |
|
|
438 |
sub x_truncate { return truncate(fixup(shift),shift) ? 0 : -$! ; } |
sub x_truncate { |
439 |
|
my ( $file,$size ) = @_; |
440 |
|
|
441 |
|
#confess "no pending file $file to truncate in ", dump( $pending ) unless defined( $pending->{$file} ); |
442 |
|
|
443 |
|
my $path = tmp_path( $file ); |
444 |
|
my $rv = truncate( $path, $size ) ? 0 : -$! ; |
445 |
|
warn "## truncate( $file $size ) $path [", -s $path, "] = $rv\n" if $debug; |
446 |
|
compress_file2path( $file, $path ); |
447 |
|
|
448 |
|
return $rv; |
449 |
|
} |
450 |
|
|
451 |
sub x_utime { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; } |
sub x_utime { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; } |
452 |
|
|
453 |
sub x_mkdir { my ($name, $perm) = @_; return 0 if mkdir(fixup($name),$perm); return -$!; } |
sub x_mkdir { my ($name, $perm) = @_; return 0 if mkdir(fixup($name),$perm); return -$!; } |
465 |
|
|
466 |
sub x_release { |
sub x_release { |
467 |
my ( $file, $mode ) = @_; |
my ( $file, $mode ) = @_; |
468 |
|
|
469 |
if ( ! defined( $pending->{$file} ) ) { |
if ( ! defined( $pending->{$file} ) ) { |
470 |
warn "release $file, NO PENDING DATA\n"; |
warn "release $file, NO PENDING DATA\n"; |
471 |
return 0; |
return 0; |
472 |
} elsif ( ! defined( $pending->{$file}->{write} ) ) { |
} elsif ( ! defined( $pending->{$file}->{write} ) ) { |
473 |
warn "release $file, not written into\n"; |
warn "release $file, not written into\n"; |
474 |
} elsif ( defined( $pending->{$file}->{open} ) && $pending->{$file}->{open} == 1 ) { |
} elsif ( $file =~ m#\Q/.fuse_hidden\E# ) { |
475 |
close( $pending->{$file}->{fh} ) || warn "can't close $file: $!"; |
warn "release internal $file\n" if $debug; |
476 |
my $path = $pending->{$file}->{path} || confess "no path for $file ? ", dump( $pending ); |
} else { |
477 |
my $dest = fixup( $file ); |
compress_file2path( $file ); |
478 |
|
} |
|
# cleanup old compressed copy |
|
|
if ( $dest =~ /\.gz$/ ) { |
|
|
warn "## remove old $dest\n"; |
|
|
unlink_all( $file ) || confess "can't remove $dest: $!"; |
|
|
$dest =~ s/\.gz$//; |
|
|
} |
|
479 |
|
|
480 |
if ( $file =~ $skip_extensions_regex ) { |
$pending->{$file}->{open}--; |
481 |
warn "release $file $mode -- uncompressed\n"; |
if ( $pending->{$file}->{open} == 0 ) { |
|
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
|
|
} elsif ( -s $path < $min_compress_size ) { |
|
|
warn "release $file -- uncompressed, too small ", -s $path, " bytes\n"; |
|
|
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
|
|
} else { |
|
|
warn "release $file $mode -- compressing\n"; |
|
482 |
|
|
483 |
|
my $path = fixup( $file ); |
484 |
|
|
485 |
file_copy( '<', $path, '>:gzip', $dest . '.gz' ); |
if ( my $old_mode = $pending->{$file}->{mode} ) { |
486 |
|
chmod $old_mode, $path || confess "can't chmod $old_mode $path"; |
487 |
|
warn "### restored mode $old_mode $path\n"; |
488 |
|
|
|
# FIXME add timeout to remove uncompressed version? |
|
|
unlink_all( $file ) || warn "can't remove $path: $!"; |
|
489 |
} |
} |
490 |
} else { |
|
491 |
warn "release $file, but still used ", $pending->{$file}->{open} , " times, delaying compression\n"; |
warn "## cleanup pending $file [", -s $path, "]\n" if $debug; |
492 |
$pending->{$file}->{open}--; |
delete( $pending->{$file} ); |
|
return 0; |
|
493 |
} |
} |
494 |
delete( $pending->{$file} ); |
|
495 |
return 0; |
return 0; |
496 |
} |
} |
497 |
|
|
519 |
statfs =>"main::x_statfs", |
statfs =>"main::x_statfs", |
520 |
release =>"main::x_release", |
release =>"main::x_release", |
521 |
# threaded=>1, |
# threaded=>1, |
522 |
# debug => 1, |
debug => $fuse_debug, |
523 |
); |
); |