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: $!"; |
127 |
sub x_open { |
sub x_open { |
128 |
my ($file) = shift; |
my ($file) = shift; |
129 |
my ($mode) = shift; |
my ($mode) = shift; |
130 |
|
|
131 |
|
if ( $file eq '/.debug' ) { |
132 |
|
my $path = $mount->{from} . '/.debug'; |
133 |
|
open( my $debug, '>', $path ) || die "can't open $path: $!"; |
134 |
|
my $dump = dump( $pending ); |
135 |
|
print $debug "pending = $dump\n"; |
136 |
|
close($debug); |
137 |
|
$pending->{'/.debug'}->{path} = $path; |
138 |
|
warn "## created dump $path $dump\n"; |
139 |
|
return 0; |
140 |
|
} |
141 |
|
|
142 |
$pending->{$file}->{open}++; |
$pending->{$file}->{open}++; |
143 |
|
|
144 |
my $mode_desc = { |
my $mode_desc = { |
146 |
rdwr => $mode && O_RDWR, |
rdwr => $mode && O_RDWR, |
147 |
append => $mode && O_APPEND, |
append => $mode && O_APPEND, |
148 |
create => $mode && O_CREAT, |
create => $mode && O_CREAT, |
149 |
|
trunc => $mode && O_TRUNC, |
150 |
}; |
}; |
151 |
warn "# open( $file, $mode ) pending: ", $pending->{$file}->{open}, " mode: ", dump( $mode_desc ),"\n"; |
my $path = fixup($file); |
152 |
|
warn "# open( $file, $mode ) pending: ", $pending->{$file}->{open}, " mode $mode: ", dump( $mode_desc )," $path [", -s $path, "]\n"; |
153 |
my $fh; |
my $fh; |
154 |
|
|
|
my $path = fixup($file); |
|
155 |
my $tmp = $mount->{tmp} . '/' . $file; |
my $tmp = $mount->{tmp} . '/' . $file; |
156 |
if ( -e $tmp ) { |
if ( -e $tmp ) { |
157 |
$path = $tmp; |
$path = $tmp; |
162 |
file_copy( '<:gzip', $path, '>', $tmp ); |
file_copy( '<:gzip', $path, '>', $tmp ); |
163 |
$path = $tmp; |
$path = $tmp; |
164 |
} |
} |
165 |
warn ">>> open abs path: $path ", -s $path, " bytes\n"; |
warn ">>> open abs path: $path [", -e $path ? -s $path : 'new' , "]\n"; |
166 |
return -$! unless sysopen($fh , $path, $mode); |
return -$! unless sysopen($fh , $path, $mode); |
167 |
|
warn ">>> after open [",-s $path, "]\n"; |
168 |
|
close($fh); |
169 |
|
|
170 |
$pending->{$file}->{path} = $path; |
$pending->{$file}->{path} = $path; |
171 |
return 0; |
return 0; |
176 |
my ($rv) = -ENOSYS(); |
my ($rv) = -ENOSYS(); |
177 |
my $path = fixup( $file ); |
my $path = fixup( $file ); |
178 |
|
|
179 |
|
confess "no pending file $file ", dump( $pending ) unless defined( $pending->{$file} ); |
180 |
|
|
181 |
return -ENOENT() unless -e $path; |
return -ENOENT() unless -e $path; |
182 |
|
|
183 |
my $fh = new IO::File; |
my $fh = new IO::File; |
196 |
my $rv; |
my $rv; |
197 |
my $path = fixup($file); |
my $path = fixup($file); |
198 |
|
|
199 |
|
confess "no pending file $file ", dump( $pending ) unless defined( $pending->{$file} ); |
200 |
|
|
201 |
return -ENOENT() unless -e $path; |
return -ENOENT() unless -e $path; |
202 |
|
|
203 |
my $fh = new IO::File; |
my $fh = new IO::File; |
207 |
warn "## ", $pending->{$file}->{path}, " $off ",length( $buf ), "\n" if $debug; |
warn "## ", $pending->{$file}->{path}, " $off ",length( $buf ), "\n" if $debug; |
208 |
} |
} |
209 |
$rv = -ENOSYS() unless $rv; |
$rv = -ENOSYS() unless $rv; |
210 |
|
close($fh); |
211 |
return length($buf); |
return length($buf); |
212 |
} |
} |
213 |
|
|
245 |
return $err; |
return $err; |
246 |
} |
} |
247 |
|
|
248 |
sub x_truncate { return truncate(fixup(shift),shift) ? 0 : -$! ; } |
sub x_truncate { |
249 |
|
my ( $file,$size ) = @_; |
250 |
|
my $path = fixup($file); |
251 |
|
my $rv = truncate( $path, $size ) ? 0 : -$! ; |
252 |
|
if ( $path =~ m/\.gz$/ ) { |
253 |
|
my $no_gz = $path; |
254 |
|
$no_gz =~ s/\.gz$//; |
255 |
|
rename $path, $no_gz || confess "can't rename $path -> $no_gz: $!"; |
256 |
|
} |
257 |
|
warn "## truncate( $file $size ) $path [", -s $path, "]\n"; |
258 |
|
return $rv; |
259 |
|
} |
260 |
sub x_utime { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; } |
sub x_utime { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; } |
261 |
|
|
262 |
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 -$!; } |
294 |
warn "release $file $mode -- uncompressed\n"; |
warn "release $file $mode -- uncompressed\n"; |
295 |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
296 |
} elsif ( -s $path < $min_compress_size ) { |
} elsif ( -s $path < $min_compress_size ) { |
297 |
warn "release $file -- uncompressed, too small ", -s $path, " bytes\n"; |
warn "release $file -- uncompressed, too small [", -s $path, "]\n"; |
298 |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); |
299 |
} else { |
} else { |
300 |
warn "release $file $mode -- compressing\n"; |
warn "release $file $mode -- compressing\n"; |
303 |
file_copy( '<', $path, '>:gzip', $dest . '.gz' ); |
file_copy( '<', $path, '>:gzip', $dest . '.gz' ); |
304 |
|
|
305 |
# FIXME add timeout to remove uncompressed version? |
# FIXME add timeout to remove uncompressed version? |
306 |
|
# FIXME leave uncompressed file if smaller than compressed |
307 |
unlink $path || warn "can't remove $path: $!"; |
unlink $path || warn "can't remove $path: $!"; |
308 |
} |
} |
309 |
} else { |
} else { |
310 |
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; |
|
311 |
} |
} |
312 |
delete( $pending->{$file} ); |
$pending->{$file}->{open}--; |
313 |
|
if ( $pending->{$file}->{open} == 0 ) { |
314 |
|
warn "## cleanup pending $file [", -s fixup($file), "]\n" if $debug; |
315 |
|
delete( $pending->{$file} ); |
316 |
|
} |
317 |
return 0; |
return 0; |
318 |
} |
} |
319 |
|
|