42 |
|
|
43 |
my $pending; |
my $pending; |
44 |
|
|
45 |
|
sub real_name { |
46 |
|
my ( $dir, $name ) = @_; |
47 |
|
if ( -e "$dir/${name}.gz" ) { |
48 |
|
return "${name}.gz"; |
49 |
|
} |
50 |
|
return $name; |
51 |
|
} |
52 |
|
|
53 |
sub fixup { |
sub fixup { |
54 |
my ( $path ) = @_; |
my ( $path ) = @_; |
55 |
my $full = $mount->{from} . '/' . $path; |
return $mount->{from} . '/' . real_name( $mount->{from}, $path ); |
|
if ( -e $full . '.gz' ) { |
|
|
return $full . '.gz'; |
|
|
} |
|
|
return $full; |
|
56 |
} |
} |
57 |
|
|
58 |
sub original_name { |
sub original_name { |
222 |
|
|
223 |
sub err { return (-shift || -$!) } |
sub err { return (-shift || -$!) } |
224 |
|
|
225 |
sub x_readlink { return readlink(fixup(shift)); } |
sub x_readlink { return readlink(fixup(shift)); } |
226 |
|
|
227 |
sub x_unlink { |
sub x_unlink { |
228 |
my $file = shift; |
my $file = shift; |
229 |
my $path = fixup( $file ); |
my $path = fixup( $file ); |
243 |
return 0; |
return 0; |
244 |
} |
} |
245 |
|
|
246 |
sub x_symlink { return symlink(shift,fixup(shift)) ? 0 : -$!; } |
sub x_symlink { |
247 |
|
my ($from,$to) = @_; |
248 |
|
|
249 |
|
my $from_path = $from; #fixup( $from ); |
250 |
|
my $to_path = fixup( $to ); |
251 |
|
|
252 |
|
my $rv = symlink( $from_path, $to_path ) ? 0 : -$!; |
253 |
|
warn "# symlink( $from_path -> $to_path ) = $rv\n" if $debug; |
254 |
|
|
255 |
|
my $tmp = $mount->{tmp} . '/' . $from; |
256 |
|
if ( -e $tmp ) { |
257 |
|
my $tmp_to = $mount->{$tmp} . '/' . $to; |
258 |
|
symlink( $tmp, $tmp_to ) || confess "can't symlink $tmp -> $tmp_to: $!"; |
259 |
|
} |
260 |
|
return $rv; |
261 |
|
} |
262 |
|
|
263 |
|
sub x_link { |
264 |
|
my ($from,$to) = @_; |
265 |
|
|
266 |
|
my $from_path = fixup($from); |
267 |
|
my $to_path = fixup($to); |
268 |
|
$to_path .= '.gz' if ( $from_path =~ m/\.gz$/ && $to_path !~ m/\.gz$/ ); |
269 |
|
|
270 |
|
my $rv = link( $from_path, $to_path ) ? 0 : -$!; |
271 |
|
|
272 |
|
warn "# link( $from_path -> $to_path ) = $rv\n" if $debug; |
273 |
|
|
274 |
|
return $rv; |
275 |
|
} |
276 |
|
|
277 |
sub x_rename { |
sub x_rename { |
278 |
my ($old,$new) = @_; |
my ($old,$new) = @_; |
306 |
|
|
307 |
return $err; |
return $err; |
308 |
} |
} |
|
sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! } |
|
309 |
|
|
310 |
sub x_chown { |
sub x_chown { |
311 |
my ($file,$uid,$gid) = @_; |
my ($file,$uid,$gid) = @_; |
341 |
} |
} |
342 |
warn "## truncate( $file $size ) $path [", -s $path, "] = $rv\n" if $debug; |
warn "## truncate( $file $size ) $path [", -s $path, "] = $rv\n" if $debug; |
343 |
$pending->{$file}->{write}++; |
$pending->{$file}->{write}++; |
344 |
|
|
345 |
|
my $tmp = $mount->{tmp} . '/' . $file; |
346 |
|
truncate( $tmp, $size ) if -e $tmp; |
347 |
|
|
348 |
return $rv; |
return $rv; |
349 |
} |
} |
350 |
sub x_utime { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; } |
sub x_utime { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; } |
388 |
} |
} |
389 |
|
|
390 |
if ( $file =~ $skip_extensions_regex ) { |
if ( $file =~ $skip_extensions_regex ) { |
391 |
warn "release $file [",-s $path,"] skipped compression\n"; |
warn "release $path [",-s $path,"] skipped compression\n"; |
392 |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
393 |
} elsif ( -s $path < $min_compress_size ) { |
} elsif ( -s $path < $min_compress_size ) { |
394 |
warn "release $file [",-s $path,"] uncompressed, too small\n"; |
warn "release $path [",-s $path,"] uncompressed, too small\n"; |
395 |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
396 |
} else { |
} else { |
397 |
warn "release $file [",-s $path,"] compressing\n"; |
warn "release $path [",-s $path,"] compressing\n"; |
398 |
|
|
399 |
my $comp = $dest . '.gz'; |
my $comp = $dest . '.gz'; |
400 |
file_copy( '<', $path, '>:gzip', $comp ); |
file_copy( '<', $path, '>:gzip', $comp ); |
403 |
|
|
404 |
if ( $size_path <= $size_comp ) { |
if ( $size_path <= $size_comp ) { |
405 |
warn ">>> $size_path <= $size_comp leaving uncompressed\n"; |
warn ">>> $size_path <= $size_comp leaving uncompressed\n"; |
406 |
unlink $comp || warn "can't reamove: $comp: $!"; |
unlink $comp || confess "can't remove: $comp: $!"; |
407 |
} else { |
} else { |
408 |
warn ">>> compressed $size_path -> $size_comp ",int(($size_comp * 100) / $size_path),"%\n"; |
warn ">>> compressed $size_path -> $size_comp ",int(($size_comp * 100) / $size_path),"%\n"; |
409 |
# FIXME add timeout to remove uncompressed version? |
# FIXME add timeout to remove uncompressed version? |
410 |
unlink $path || warn "can't remove $path: $!"; |
unlink $path || confess "can't remove $path: $!"; |
411 |
} |
} |
412 |
} |
} |
413 |
} else { |
} else { |