prevent multiple umounts by keeping mounted flag
git-svn-id: svn://svn.rot13.org/fuse_dbi/trunk@26
17f4e80c-d0e0-0310-8903-
bfc3ae804c12
# save (some) arguments in self
foreach (qw(mount invalidate)) {
$self->{$_} = $arg->{$_};
# save (some) arguments in self
foreach (qw(mount invalidate)) {
$self->{$_} = $arg->{$_};
- $fuse_self->{$_} = $arg->{$_};
}
foreach (qw(filenames read update)) {
}
foreach (qw(filenames read update)) {
$dbh = DBI->connect($arg->{'dsn'},$arg->{'user'},$arg->{'password'}, {AutoCommit => 0, RaiseError => 1}) || die $DBI::errstr;
$dbh = DBI->connect($arg->{'dsn'},$arg->{'user'},$arg->{'password'}, {AutoCommit => 0, RaiseError => 1}) || die $DBI::errstr;
- $sth->{filenames} = $dbh->prepare($arg->{'filenames'}) || die $dbh->errstr();
+ $sth->{'filenames'} = $dbh->prepare($arg->{'filenames'}) || die $dbh->errstr();
$sth->{'read'} = $dbh->prepare($arg->{'read'}) || die $dbh->errstr();
$sth->{'update'} = $dbh->prepare($arg->{'update'}) || die $dbh->errstr();
$sth->{'read'} = $dbh->prepare($arg->{'read'}) || die $dbh->errstr();
$sth->{'update'} = $dbh->prepare($arg->{'update'}) || die $dbh->errstr();
+
+ $self->{'sth'} = $sth;
+
+ $self->{'read_filenames'} = sub { $self->read_filenames };
+ $self->{'mounted'} = 1;
+
+ $fuse_self = \$self;
+
Fuse::main(
mountpoint=>$arg->{'mount'},
getattr=>\&e_getattr,
Fuse::main(
mountpoint=>$arg->{'mount'},
getattr=>\&e_getattr,
utime=>\&e_utime,
truncate=>\&e_truncate,
unlink=>\&e_unlink,
utime=>\&e_utime,
truncate=>\&e_truncate,
unlink=>\&e_unlink,
+
+ $self->{'mounted'} = 0;
exit(0) if ($arg->{'fork'});
exit(0) if ($arg->{'fork'});
sub umount {
my $self = shift;
sub umount {
my $self = shift;
- system "fusermount -u ".$self->{'mount'} || croak "umount error: $!";
+ if ($self->{'mounted'}) {
+ system "fusermount -u ".$self->{'mount'} || croak "umount error: $!";
+ }
-#$SIG{'INT'} = sub {
-# print STDERR "umount called by SIG INT\n";
-# umount;
-#};
+$SIG{'INT'} = sub {
+ print STDERR "umount called by SIG INT\n";
+ umount;
+};
sub DESTROY {
my $self = shift;
sub DESTROY {
my $self = shift;
+ return if (! $self->{'mounted'});
print STDERR "umount called by DESTROY\n";
$self->umount;
}
print STDERR "umount called by DESTROY\n";
$self->umount;
}
sub read_filenames {
my $self = shift;
sub read_filenames {
my $self = shift;
+ my $sth = $self->{'sth'} || die "no sth argument";
+
# create empty filesystem
(%files) = (
'.' => {
# create empty filesystem
(%files) = (
'.' => {
$sth->{'read'}->execute($id) || die $sth->{'read'}->errstr;
$files{$file}{cont} = $sth->{'read'}->fetchrow_array;
$sth->{'read'}->execute($id) || die $sth->{'read'}->errstr;
$files{$file}{cont} = $sth->{'read'}->fetchrow_array;
+ $files{$file}{ctime} = time();
print "file '$file' content [",length($files{$file}{cont})," bytes] read in cache\n";
}
print "file '$file' content [",length($files{$file}{cont})," bytes] read in cache\n";
}
}
print "updated '$file' [",$files{$file}{id},"]\n";
}
print "updated '$file' [",$files{$file}{id},"]\n";
- $fuse_self->{'invalidate'}->() if (ref $fuse_self->{'invalidate'});
+ $$fuse_self->{'invalidate'}->() if (ref $$fuse_self->{'invalidate'});
sub e_unlink {
my $file = filename_fixup(shift);
sub e_unlink {
my $file = filename_fixup(shift);
- return -ENOENT() unless exists($files{$file});
-
- print "unlink '$file' will invalidate cache\n";
-
- read_content($file,$files{$file}{id});
+ if (exists( $dirs{$file} )) {
+ print "unlink '$file' will re-read template names\n";
+ print Dumper($fuse_self);
+ $$fuse_self->{'read_filenames'}->();
+ return 0;
+ } elsif (exists( $files{$file} )) {
+ print "unlink '$file' will invalidate cache\n";
+ read_content($file,$files{$file}{id});
+ return 0;
+ }