--- fuse-comp.pl 2007/07/09 16:20:07 20 +++ fuse-comp.pl 2007/07/09 21:41:58 23 @@ -12,6 +12,15 @@ use Data::Dump qw/dump/; use Carp qw/confess/; use IO::File; +use Getopt::Long; + +my $debug = 0; +my $fuse_debug = 0; + +GetOptions( + 'debug+' => \$debug, + 'fuse-debug+' => \$fuse_debug, +); my $mount = { from => '/tmp/comp', @@ -159,15 +168,24 @@ my $dest_path = $tmp; $dest_path =~ s!/[^/]+$!!; #!vim-fix mkpath $dest_path unless -e $dest_path; - file_copy( '<:gzip', $path, '>', $tmp ); + if ( -s $path ) { + file_copy( '<:gzip', $path, '>', $tmp ) + } else { + warn "ERROR: filesystem corruption, $path is zero size\n"; + } $path = $tmp; } - warn "<<< open abs path: $path [", -e $path ? -s $path : 'new' , "]\n"; - return -$! unless sysopen($fh , $path, $mode); - close($fh); - $pending->{$file}->{path} = $path; - return 0; + if ( sysopen($fh , $path, $mode) ) { + close($fh) || confess "can't close $path: $!"; + warn "<<< open $path [", -e $path ? -s $path : 'new' , "]\n"; + $pending->{$file}->{path} = $path; + return 0; + } else { + warn "ERROR: can't open $path : $!"; + return -$!; + } + } sub x_read { @@ -238,8 +256,9 @@ my $path = $pending->{$old}->{path}; $path =~ s/\Q$old\E/$new/; $pending->{$new}->{path} = $path; + $pending->{$old}->{path} = $path; - delete( $pending->{$old} ); + #delete( $pending->{$old} ); } return $err; @@ -274,7 +293,7 @@ $no_gz =~ s/\.gz$//; rename $path, $no_gz || confess "can't rename $path -> $no_gz: $!"; } - warn "## truncate( $file $size ) $path [", -s $path, "]\n"; + warn "## truncate( $file $size ) $path [", -s $path, "] = $rv\n" if $debug; $pending->{$file}->{write}++; return $rv; } @@ -369,5 +388,5 @@ statfs =>"main::x_statfs", release =>"main::x_release", # threaded=>1, -# debug => 1, + debug => $fuse_debug, );