--- fuse-comp.pl 2007/07/08 21:03:26 10 +++ fuse-comp.pl 2007/07/09 11:12:48 13 @@ -103,13 +103,13 @@ sub file_copy { my ( $s_opt, $s_path, $d_opt, $d_path ) = @_; - 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"; open(my $s, $s_opt, $s_path ) || confess "can't open $s_path: $!\npending = ", dump( $pending ); open(my $d, $d_opt, $d_path ) || confess "can't open $d_path: $!"; my $buff; while( read( $s, $buff, 65535 ) ) { print $d $buff || confess "can't write into $d_path: $!"; - warn ">> ", length($buff), " bytes, offset ", tell($s), " -> ", tell($d), "\n" if $debug; + warn ">> [", length($buff), "] offset ", tell($s), " -> ", tell($d), "\n" if $debug; } close($d) || warn "can't close $d_path: $!"; close($s) || warn "can't close $s_path: $!"; @@ -127,6 +127,18 @@ sub x_open { my ($file) = shift; my ($mode) = shift; + + if ( $file eq '/.debug' ) { + my $path = $mount->{from} . '/.debug'; + open( my $debug, '>', $path ) || die "can't open $path: $!"; + my $dump = dump( $pending ); + print $debug "pending = $dump\n"; + close($debug); + $pending->{'/.debug'}->{path} = $path; + warn "## created dump $path $dump\n"; + return 0; + } + $pending->{$file}->{open}++; my $mode_desc = { @@ -149,8 +161,9 @@ file_copy( '<:gzip', $path, '>', $tmp ); $path = $tmp; } - warn ">>> open abs path: $path ", -s $path, " bytes\n"; + warn ">>> open abs path: $path [", -s $path, "]\n"; return -$! unless sysopen($fh , $path, $mode); + close($fh); $pending->{$file}->{path} = $path; return 0; @@ -161,6 +174,8 @@ my ($rv) = -ENOSYS(); my $path = fixup( $file ); + confess "no pending file $file ", dump( $pending ) unless defined( $pending->{$file} ); + return -ENOENT() unless -e $path; my $fh = new IO::File; @@ -179,6 +194,8 @@ my $rv; my $path = fixup($file); + confess "no pending file $file ", dump( $pending ) unless defined( $pending->{$file} ); + return -ENOENT() unless -e $path; my $fh = new IO::File; @@ -188,6 +205,7 @@ warn "## ", $pending->{$file}->{path}, " $off ",length( $buf ), "\n" if $debug; } $rv = -ENOSYS() unless $rv; + close($fh); return length($buf); } @@ -263,7 +281,7 @@ warn "release $file $mode -- uncompressed\n"; file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); } elsif ( -s $path < $min_compress_size ) { - warn "release $file -- uncompressed, too small ", -s $path, " bytes\n"; + warn "release $file -- uncompressed, too small [", -s $path, "]\n"; file_copy( '<', $path, '>', $dest ) if ( $path ne $dest ); } else { warn "release $file $mode -- compressing\n"; @@ -276,10 +294,12 @@ } } else { warn "release $file, but still used ", $pending->{$file}->{open} , " times, delaying compression\n"; - $pending->{$file}->{open}--; - return 0; } - delete( $pending->{$file} ); + $pending->{$file}->{open}--; + if ( $pending->{$file}->{open} == 0 ) { + warn "## cleanup pending $file [", -s fixup($file), "]\n" if $debug; + delete( $pending->{$file} ); + } return 0; }