144 |
# be a problem. |
# be a problem. |
145 |
my $fuse_self; |
my $fuse_self; |
146 |
|
|
147 |
|
my $debug = 0; |
148 |
|
|
149 |
sub mount { |
sub mount { |
150 |
my $class = shift; |
my $class = shift; |
151 |
my $self = {}; |
my $self = {}; |
197 |
|
|
198 |
$sth->{'filenames'} = $dbh->prepare($arg->{'filenames'}) || die $dbh->errstr(); |
$sth->{'filenames'} = $dbh->prepare($arg->{'filenames'}) || die $dbh->errstr(); |
199 |
|
|
|
|
|
200 |
$self->{'sth'} = $sth; |
$self->{'sth'} = $sth; |
201 |
|
$self->{'dbh'} = $dbh; |
202 |
|
|
203 |
$self->{'read_filenames'} = sub { $self->read_filenames }; |
$self->{'read_filenames'} = sub { $self->read_filenames }; |
204 |
$self->read_filenames; |
$self->read_filenames; |
214 |
} |
} |
215 |
} |
} |
216 |
|
|
217 |
$fuse_self = \$self; |
$fuse_self = $self; |
218 |
|
|
219 |
Fuse::main( |
Fuse::main( |
220 |
mountpoint=>$arg->{'mount'}, |
mountpoint=>$arg->{'mount'}, |
228 |
truncate=>\&e_truncate, |
truncate=>\&e_truncate, |
229 |
unlink=>\&e_unlink, |
unlink=>\&e_unlink, |
230 |
rmdir=>\&e_unlink, |
rmdir=>\&e_unlink, |
231 |
debug=>1, |
debug=>$debug, |
232 |
); |
); |
233 |
|
|
234 |
exit(0) if ($arg->{'fork'}); |
exit(0) if ($arg->{'fork'}); |
279 |
|
|
280 |
if ($self->{'mount'} && $self->is_mounted) { |
if ($self->{'mount'} && $self->is_mounted) { |
281 |
system "( fusermount -u ".$self->{'mount'}." 2>&1 ) >/dev/null"; |
system "( fusermount -u ".$self->{'mount'}." 2>&1 ) >/dev/null"; |
282 |
|
sleep 1; |
283 |
if ($self->is_mounted) { |
if ($self->is_mounted) { |
284 |
system "sudo umount ".$self->{'mount'} || |
system "sudo umount ".$self->{'mount'} || |
285 |
return 0; |
return 0; |
291 |
} |
} |
292 |
|
|
293 |
$SIG{'INT'} = sub { |
$SIG{'INT'} = sub { |
294 |
if ($fuse_self && $$fuse_self->umount) { |
if ($fuse_self && $fuse_self->can('umount')) { |
295 |
print STDERR "umount called by SIG INT\n"; |
print STDERR "umount called by SIG INT\n"; |
296 |
} |
} |
297 |
}; |
}; |
298 |
|
|
299 |
$SIG{'QUIT'} = sub { |
$SIG{'QUIT'} = sub { |
300 |
if ($fuse_self && $$fuse_self->umount) { |
if ($fuse_self && $fuse_self->can('umount')) { |
301 |
print STDERR "umount called by SIG QUIT\n"; |
print STDERR "umount called by SIG QUIT\n"; |
302 |
} |
} |
303 |
}; |
}; |
447 |
|
|
448 |
warn "file: $file\n", Dumper($fuse_self); |
warn "file: $file\n", Dumper($fuse_self); |
449 |
|
|
450 |
my @args = $$fuse_self->{'read_ref'}->($files->{$file}); |
my @args = $fuse_self->{'read_ref'}->($files->{$file}); |
451 |
my $sql = shift @args || die "need SQL for $file"; |
my $sql = shift @args || die "need SQL for $file"; |
452 |
|
|
453 |
$$fuse_self->{'read_sth'}->{$sql} ||= $$fuse_self->{sth}->prepare($sql) || die $dbh->errstr(); |
$fuse_self->{'read_sth'}->{$sql} ||= $fuse_self->{dbh}->prepare($sql) || die $dbh->errstr(); |
454 |
my $sth = $$fuse_self->{'read_sth'}->{$sql} || die; |
my $sth = $fuse_self->{'read_sth'}->{$sql} || die; |
455 |
|
|
456 |
$sth->execute(@args) || die $sth->errstr; |
$sth->execute(@args) || die $sth->errstr; |
457 |
$files->{$file}->{cont} = $sth->fetchrow_array; |
$files->{$file}->{cont} = $sth->fetchrow_array; |
520 |
$files->{$file}->{id} |
$files->{$file}->{id} |
521 |
); |
); |
522 |
|
|
523 |
my @args = $$fuse_self->{'update_ref'}->($files->{$file}); |
my @args = $fuse_self->{'update_ref'}->($files->{$file}); |
524 |
|
|
525 |
my $sql = shift @args || die "need SQL for $file"; |
my $sql = shift @args || die "need SQL for $file"; |
526 |
|
|
527 |
my $sth = $$fuse_self->{'update_sth'}->{$sql} |
unshift @args, $files->{$file}->{cont} if ($#args == 0); |
528 |
||= $$fuse_self->{sth}->prepare($sql) |
|
529 |
|
warn "## SQL: $sql\n# files->{$file} = ", Dumper($files->{$file}), $/ if ($debug); |
530 |
|
|
531 |
|
my $sth = $fuse_self->{'update_sth'}->{$sql} |
532 |
|
||= $fuse_self->{dbh}->prepare($sql) |
533 |
|| die $dbh->errstr(); |
|| die $dbh->errstr(); |
534 |
|
|
535 |
if (!$sth->execute(@args)) { |
if (!$sth->execute(@args)) { |
544 |
} |
} |
545 |
print "updated '$file' [",$files->{$file}->{id},"]\n"; |
print "updated '$file' [",$files->{$file}->{id},"]\n"; |
546 |
|
|
547 |
$$fuse_self->{'invalidate'}->() if (ref $$fuse_self->{'invalidate'}); |
$fuse_self->{'invalidate'}->() if ($fuse_self->can('invalidate')); |
548 |
} |
} |
549 |
return 1; |
return 1; |
550 |
} |
} |
627 |
# if (exists( $dirs{$file} )) { |
# if (exists( $dirs{$file} )) { |
628 |
# print "unlink '$file' will re-read template names\n"; |
# print "unlink '$file' will re-read template names\n"; |
629 |
# print Dumper($fuse_self); |
# print Dumper($fuse_self); |
630 |
# $$fuse_self->{'read_filenames'}->(); |
# $fuse_self->{'read_filenames'}->(); |
631 |
# return 0; |
# return 0; |
632 |
if (exists( $files->{$file} )) { |
if (exists( $files->{$file} )) { |
633 |
print "unlink '$file' will invalidate cache\n"; |
print "unlink '$file' will invalidate cache\n"; |