12 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
13 |
use Carp qw/confess/; |
use Carp qw/confess/; |
14 |
use IO::File; |
use IO::File; |
15 |
|
use Getopt::Long; |
16 |
|
|
17 |
|
my $debug = 0; |
18 |
|
my $fuse_debug = 0; |
19 |
|
|
20 |
|
GetOptions( |
21 |
|
'debug+' => \$debug, |
22 |
|
'fuse-debug+' => \$fuse_debug, |
23 |
|
); |
24 |
|
|
25 |
my $mount = { |
my $mount = { |
26 |
from => '/tmp/comp', |
from => '/tmp/comp', |
28 |
tmp => '/dev/shm/comp', |
tmp => '/dev/shm/comp', |
29 |
}; |
}; |
30 |
|
|
|
my $debug = shift @ARGV; |
|
|
|
|
31 |
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; |
32 |
|
|
33 |
# don't compress files smaller than this |
# don't compress files smaller than this |
166 |
my $dest_path = $tmp; |
my $dest_path = $tmp; |
167 |
$dest_path =~ s!/[^/]+$!!; #!vim-fix |
$dest_path =~ s!/[^/]+$!!; #!vim-fix |
168 |
mkpath $dest_path unless -e $dest_path; |
mkpath $dest_path unless -e $dest_path; |
169 |
file_copy( '<:gzip', $path, '>', $tmp ); |
if ( -s $path ) { |
170 |
|
file_copy( '<:gzip', $path, '>', $tmp ) |
171 |
|
} else { |
172 |
|
warn "ERROR: filesystem corruption, $path is zero size\n"; |
173 |
|
} |
174 |
$path = $tmp; |
$path = $tmp; |
175 |
} |
} |
|
warn "<<< open abs path: $path [", -e $path ? -s $path : 'new' , "]\n"; |
|
|
return -$! unless sysopen($fh , $path, $mode); |
|
|
close($fh); |
|
176 |
|
|
177 |
$pending->{$file}->{path} = $path; |
if ( sysopen($fh , $path, $mode) ) { |
178 |
return 0; |
close($fh) || confess "can't close $path: $!"; |
179 |
|
warn "<<< open $path [", -e $path ? -s $path : 'new' , "]\n"; |
180 |
|
$pending->{$file}->{path} = $path; |
181 |
|
return 0; |
182 |
|
} else { |
183 |
|
warn "ERROR: can't open $path : $!"; |
184 |
|
return -$!; |
185 |
|
} |
186 |
|
|
187 |
} |
} |
188 |
|
|
189 |
sub x_read { |
sub x_read { |
254 |
my $path = $pending->{$old}->{path}; |
my $path = $pending->{$old}->{path}; |
255 |
$path =~ s/\Q$old\E/$new/; |
$path =~ s/\Q$old\E/$new/; |
256 |
$pending->{$new}->{path} = $path; |
$pending->{$new}->{path} = $path; |
257 |
|
$pending->{$old}->{path} = $path; |
258 |
|
|
259 |
delete( $pending->{$old} ); |
#delete( $pending->{$old} ); |
260 |
} |
} |
261 |
|
|
262 |
return $err; |
return $err; |
291 |
$no_gz =~ s/\.gz$//; |
$no_gz =~ s/\.gz$//; |
292 |
rename $path, $no_gz || confess "can't rename $path -> $no_gz: $!"; |
rename $path, $no_gz || confess "can't rename $path -> $no_gz: $!"; |
293 |
} |
} |
294 |
warn "## truncate( $file $size ) $path [", -s $path, "]\n"; |
warn "## truncate( $file $size ) $path [", -s $path, "] = $rv\n" if $debug; |
295 |
$pending->{$file}->{write}++; |
$pending->{$file}->{write}++; |
296 |
return $rv; |
return $rv; |
297 |
} |
} |
386 |
statfs =>"main::x_statfs", |
statfs =>"main::x_statfs", |
387 |
release =>"main::x_release", |
release =>"main::x_release", |
388 |
# threaded=>1, |
# threaded=>1, |
389 |
# debug => 1, |
debug => $fuse_debug, |
390 |
); |
); |