19 |
tmp => '/dev/shm/comp', |
tmp => '/dev/shm/comp', |
20 |
}; |
}; |
21 |
|
|
22 |
my $debug = 0; |
my $debug = shift @ARGV; |
23 |
|
|
24 |
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; |
25 |
|
|
232 |
rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!"; |
rename $tmp, $new_tmp || confess "can't rename $tmp -> $new_tmp : $!"; |
233 |
} |
} |
234 |
|
|
235 |
|
if (defined( $pending->{$old} )) { |
236 |
|
$pending->{$new} = $pending->{$old}; |
237 |
|
|
238 |
|
my $path = $pending->{$old}->{path}; |
239 |
|
$path =~ s/\Q$old\E/$new/; |
240 |
|
$pending->{$new}->{path} = $path; |
241 |
|
|
242 |
|
delete( $pending->{$old} ); |
243 |
|
} |
244 |
|
|
245 |
return $err; |
return $err; |
246 |
} |
} |
247 |
sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! } |
sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! } |
312 |
} |
} |
313 |
|
|
314 |
if ( $file =~ $skip_extensions_regex ) { |
if ( $file =~ $skip_extensions_regex ) { |
315 |
warn "release $file $mode -- uncompressed\n"; |
warn "release $file [",-s $path,"] skipped compression\n"; |
316 |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
317 |
} elsif ( -s $path < $min_compress_size ) { |
} elsif ( -s $path < $min_compress_size ) { |
318 |
warn "release $file -- uncompressed, too small [", -s $path, "]\n"; |
warn "release $file [",-s $path,"] uncompressed, too small\n"; |
319 |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
320 |
} else { |
} else { |
321 |
warn "release $file $mode -- compressing\n"; |
warn "release $file [",-s $path,"] compressing\n"; |
322 |
|
|
323 |
|
my $comp = $dest . '.gz'; |
324 |
|
file_copy( '<', $path, '>:gzip', $comp ); |
325 |
|
|
326 |
file_copy( '<', $path, '>:gzip', $dest . '.gz' ); |
my ( $size_path, $size_comp ) = ( -s $path, -s $comp ); |
327 |
|
|
328 |
# FIXME add timeout to remove uncompressed version? |
if ( $size_path <= $size_comp ) { |
329 |
# FIXME leave uncompressed file if smaller than compressed |
warn ">>> $size_path <= $size_comp leaving uncompressed\n"; |
330 |
unlink $path || warn "can't remove $path: $!"; |
unlink $comp || warn "can't reamove: $comp: $!"; |
331 |
|
} else { |
332 |
|
warn ">>> compressed $size_path -> $size_comp ",int(($size_comp * 100) / $size_path),"%\n"; |
333 |
|
# FIXME add timeout to remove uncompressed version? |
334 |
|
unlink $path || warn "can't remove $path: $!"; |
335 |
|
} |
336 |
} |
} |
337 |
} else { |
} else { |
338 |
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"; |