call umount on DESTROY, support for optional 'invalidate' code ref which
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 8 Oct 2004 20:07:12 +0000 (20:07 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 8 Oct 2004 20:07:12 +0000 (20:07 +0000)
erase templates from disk (user running fuse must have permissions on
template directory for this to work)

git-svn-id: svn://svn.rot13.org/fuse_dbi/trunk@24 17f4e80c-d0e0-0310-8903-bfc3ae804c12

DBI.pm

diff --git a/DBI.pm b/DBI.pm
index 3929145..bb42967 100755 (executable)
--- a/DBI.pm
+++ b/DBI.pm
@@ -64,6 +64,11 @@ my $ctime_start;
 sub read_filenames;
 sub fuse_module_loaded;
 
 sub read_filenames;
 sub fuse_module_loaded;
 
+# evil, evil way to solve this. It makes this module non-reentrant. But, since
+# fuse calls another copy of this script for each mount anyway, this shouldn't
+# be a problem.
+my $fuse_self;
+
 sub mount {
        my $class = shift;
        my $self = {};
 sub mount {
        my $class = shift;
        my $self = {};
@@ -77,7 +82,10 @@ sub mount {
        carp "mount needs 'mount' as mountpoint" unless ($arg->{'mount'});
 
        # save (some) arguments in self
        carp "mount needs 'mount' as mountpoint" unless ($arg->{'mount'});
 
        # save (some) arguments in self
-       $self->{$_} = $arg->{$_} foreach (qw(mount));
+       foreach (qw(mount invalidate)) {
+               $self->{$_} = $arg->{$_};
+               $fuse_self->{$_} = $arg->{$_};
+       }
 
        foreach (qw(filenames read update)) {
                carp "mount needs '$_' SQL" unless ($arg->{$_});
 
        foreach (qw(filenames read update)) {
                carp "mount needs '$_' SQL" unless ($arg->{$_});
@@ -143,6 +151,17 @@ sub umount {
        return 1;
 }
 
        return 1;
 }
 
+#$SIG{'INT'} = sub {
+#      print STDERR "umount called by SIG INT\n";
+#      umount;
+#};
+
+sub DESTROY {
+       my $self = shift;
+       print STDERR "umount called by DESTROY\n";
+       $self->umount;
+}
+
 =head2 fuse_module_loaded
 
 Checks if C<fuse> module is loaded in kernel.
 =head2 fuse_module_loaded
 
 Checks if C<fuse> module is loaded in kernel.
@@ -348,6 +367,8 @@ sub update_db {
                        return 0;
                }
                print "updated '$file' [",$files{$file}{id},"]\n";
                        return 0;
                }
                print "updated '$file' [",$files{$file}{id},"]\n";
+
+               $fuse_self->{'invalidate'}->() if (ref $fuse_self->{'invalidate'});
        }
        return 1;
 }
        }
        return 1;
 }