103 |
|
|
104 |
sub file_copy { |
sub file_copy { |
105 |
my ( $s_opt, $s_path, $d_opt, $d_path ) = @_; |
my ( $s_opt, $s_path, $d_opt, $d_path ) = @_; |
106 |
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"; |
107 |
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 ); |
108 |
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: $!"; |
109 |
my $buff; |
my $buff; |
110 |
while( read( $s, $buff, 65535 ) ) { |
while( read( $s, $buff, 65535 ) ) { |
111 |
print $d $buff || confess "can't write into $d_path: $!"; |
print $d $buff || confess "can't write into $d_path: $!"; |
112 |
warn ">> ", length($buff), " bytes, offset ", tell($s), " -> ", tell($d), "\n" if $debug; |
warn ">> [", length($buff), "] offset ", tell($s), " -> ", tell($d), "\n" if $debug; |
113 |
} |
} |
114 |
close($d) || warn "can't close $d_path: $!"; |
close($d) || warn "can't close $d_path: $!"; |
115 |
close($s) || warn "can't close $s_path: $!"; |
close($s) || warn "can't close $s_path: $!"; |
161 |
file_copy( '<:gzip', $path, '>', $tmp ); |
file_copy( '<:gzip', $path, '>', $tmp ); |
162 |
$path = $tmp; |
$path = $tmp; |
163 |
} |
} |
164 |
warn ">>> open abs path: $path ", -s $path, " bytes\n"; |
warn ">>> open abs path: $path [", -s $path, "]\n"; |
165 |
return -$! unless sysopen($fh , $path, $mode); |
return -$! unless sysopen($fh , $path, $mode); |
166 |
close($fh); |
close($fh); |
167 |
|
|
281 |
warn "release $file $mode -- uncompressed\n"; |
warn "release $file $mode -- uncompressed\n"; |
282 |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
283 |
} elsif ( -s $path < $min_compress_size ) { |
} elsif ( -s $path < $min_compress_size ) { |
284 |
warn "release $file -- uncompressed, too small ", -s $path, " bytes\n"; |
warn "release $file -- uncompressed, too small [", -s $path, "]\n"; |
285 |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
286 |
} else { |
} else { |
287 |
warn "release $file $mode -- compressing\n"; |
warn "release $file $mode -- compressing\n"; |
294 |
} |
} |
295 |
} else { |
} else { |
296 |
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"; |
|
$pending->{$file}->{open}--; |
|
|
return 0; |
|
297 |
} |
} |
298 |
delete( $pending->{$file} ); |
$pending->{$file}->{open}--; |
299 |
|
if ( $pending->{$file}->{open} == 0 ) { |
300 |
|
warn "## cleanup pending $file [", -s fixup($file), "]\n" if $debug; |
301 |
|
delete( $pending->{$file} ); |
302 |
|
} |
303 |
return 0; |
return 0; |
304 |
} |
} |
305 |
|
|