14 |
use Data::Dumper; |
use Data::Dumper; |
15 |
|
|
16 |
|
|
17 |
our $VERSION = '0.01'; |
our $VERSION = '0.02'; |
18 |
|
|
19 |
=head1 NAME |
=head1 NAME |
20 |
|
|
76 |
carp "mount needs 'dsn' to connect to (e.g. dsn => 'DBI:Pg:dbname=test')" unless ($arg->{'dsn'}); |
carp "mount needs 'dsn' to connect to (e.g. dsn => 'DBI:Pg:dbname=test')" unless ($arg->{'dsn'}); |
77 |
carp "mount needs 'mount' as mountpoint" unless ($arg->{'mount'}); |
carp "mount needs 'mount' as mountpoint" unless ($arg->{'mount'}); |
78 |
|
|
79 |
|
# save (some) arguments in self |
80 |
|
$self->{$_} = $arg->{$_} foreach (qw(mount)); |
81 |
|
|
82 |
foreach (qw(filenames read update)) { |
foreach (qw(filenames read update)) { |
83 |
carp "mount needs '$_' SQL" unless ($arg->{$_}); |
carp "mount needs '$_' SQL" unless ($arg->{$_}); |
84 |
} |
} |
86 |
$dbh = DBI->connect($arg->{'dsn'},$arg->{'user'},$arg->{'password'}, { AutoCommit => 0 }) || die $DBI::errstr; |
$dbh = DBI->connect($arg->{'dsn'},$arg->{'user'},$arg->{'password'}, { AutoCommit => 0 }) || die $DBI::errstr; |
87 |
|
|
88 |
print "start transaction\n"; |
print "start transaction\n"; |
89 |
#$dbh->begin_work || die $dbh->errstr; |
$dbh->begin_work || die $dbh->errstr; |
90 |
|
|
91 |
$sth->{filenames} = $dbh->prepare($arg->{'filenames'}) || die $dbh->errstr(); |
$sth->{filenames} = $dbh->prepare($arg->{'filenames'}) || die $dbh->errstr(); |
92 |
|
|
115 |
); |
); |
116 |
} ); |
} ); |
117 |
|
|
118 |
|
confess "Fuse::main failed" if (! $self->{'proc'}->poll); |
119 |
|
|
120 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
121 |
}; |
}; |
122 |
|
|
135 |
my $self = shift; |
my $self = shift; |
136 |
|
|
137 |
confess "no process running?" unless ($self->{'proc'}); |
confess "no process running?" unless ($self->{'proc'}); |
138 |
$self->{'proc'}->kill; |
|
139 |
|
system "fusermount -u ".$self->{'mount'} || croak "umount error: $!"; |
140 |
|
|
141 |
|
if ($self->{'proc'}->poll) { |
142 |
|
$self->{'proc'}->kill; |
143 |
|
return 1 if (! $self->{'proc'}->poll); |
144 |
|
} else { |
145 |
|
return 1; |
146 |
|
} |
147 |
} |
} |
148 |
|
|
149 |
|
|
235 |
# return as many text filenames as you like, followed by the retval. |
# return as many text filenames as you like, followed by the retval. |
236 |
print((scalar keys %files)." files total\n"); |
print((scalar keys %files)." files total\n"); |
237 |
my %out; |
my %out; |
238 |
foreach (keys %files) { |
foreach my $f (sort keys %files) { |
|
my $f = $_; |
|
|
$f =~ s/^\E$dirname\Q//; |
|
|
$f =~ s/^\///; |
|
239 |
if ($dirname) { |
if ($dirname) { |
240 |
$out{$f}++ if (/^\E$dirname\Q/ && $f =~ /^[^\/]+$/); |
if ($f =~ s/^\E$dirname\Q\///) { |
241 |
|
$out{$f}++ if ($f =~ /^[^\/]+$/); |
242 |
|
} |
243 |
} else { |
} else { |
244 |
$out{$f}++ if ($f =~ /^[^\/]+$/); |
$out{$f}++ if ($f =~ /^[^\/]+$/); |
245 |
} |
} |
248 |
$out{'no files? bug?'}++; |
$out{'no files? bug?'}++; |
249 |
} |
} |
250 |
print scalar keys %out," files in dir '$dirname'\n"; |
print scalar keys %out," files in dir '$dirname'\n"; |
251 |
|
print "## ",join(" ",keys %out),"\n"; |
252 |
return (keys %out),0; |
return (keys %out),0; |
253 |
} |
} |
254 |
|
|
324 |
|
|
325 |
sub e_write { |
sub e_write { |
326 |
my $file = filename_fixup(shift); |
my $file = filename_fixup(shift); |
327 |
my ($buf_len,$off) = @_; |
my ($buffer,$off) = @_; |
328 |
|
|
329 |
return -ENOENT() unless exists($files{$file}); |
return -ENOENT() unless exists($files{$file}); |
330 |
|
|
331 |
my $len = length($files{$file}{cont}); |
my $cont = $files{$file}{cont}; |
332 |
|
my $len = length($cont); |
333 |
|
|
334 |
print "write '$file' [$len bytes] offset $off length\n"; |
print "write '$file' [$len bytes] offset $off length ",length($buffer),"\n"; |
335 |
|
|
336 |
$files{$file}{cont} = |
$files{$file}{cont} = ""; |
337 |
substr($files{$file}{cont},0,$off) . |
|
338 |
$buf_len . |
$files{$file}{cont} .= substr($cont,0,$off) if ($off > 0); |
339 |
substr($files{$file}{cont},$off+length($buf_len)); |
$files{$file}{cont} .= $buffer; |
340 |
|
$files{$file}{cont} .= substr($cont,-($off+length($buffer))) if ($off+length($buffer) > $len); |
341 |
|
|
342 |
|
$files{$file}{size} = length($files{$file}{cont}); |
343 |
|
|
344 |
if (! update_db($file)) { |
if (! update_db($file)) { |
345 |
return -ENOSYS(); |
return -ENOSYS(); |
346 |
} else { |
} else { |
347 |
return length($buf_len); |
return length($buffer); |
348 |
} |
} |
349 |
} |
} |
350 |
|
|
352 |
my $file = filename_fixup(shift); |
my $file = filename_fixup(shift); |
353 |
my $size = shift; |
my $size = shift; |
354 |
|
|
355 |
|
print "truncate to $size\n"; |
356 |
|
|
357 |
$files{$file}{cont} = substr($files{$file}{cont},0,$size); |
$files{$file}{cont} = substr($files{$file}{cont},0,$size); |
358 |
|
$files{$file}{size} = $size; |
359 |
return 0 |
return 0 |
360 |
}; |
}; |
361 |
|
|