84 |
# save (some) arguments in self |
# save (some) arguments in self |
85 |
foreach (qw(mount invalidate)) { |
foreach (qw(mount invalidate)) { |
86 |
$self->{$_} = $arg->{$_}; |
$self->{$_} = $arg->{$_}; |
|
$fuse_self->{$_} = $arg->{$_}; |
|
87 |
} |
} |
88 |
|
|
89 |
foreach (qw(filenames read update)) { |
foreach (qw(filenames read update)) { |
104 |
|
|
105 |
$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; |
106 |
|
|
107 |
$sth->{filenames} = $dbh->prepare($arg->{'filenames'}) || die $dbh->errstr(); |
$sth->{'filenames'} = $dbh->prepare($arg->{'filenames'}) || die $dbh->errstr(); |
108 |
|
|
109 |
$sth->{'read'} = $dbh->prepare($arg->{'read'}) || die $dbh->errstr(); |
$sth->{'read'} = $dbh->prepare($arg->{'read'}) || die $dbh->errstr(); |
110 |
$sth->{'update'} = $dbh->prepare($arg->{'update'}) || die $dbh->errstr(); |
$sth->{'update'} = $dbh->prepare($arg->{'update'}) || die $dbh->errstr(); |
111 |
|
|
112 |
|
|
113 |
|
$self->{'sth'} = $sth; |
114 |
|
|
115 |
|
$self->{'read_filenames'} = sub { $self->read_filenames }; |
116 |
$self->read_filenames; |
$self->read_filenames; |
117 |
|
|
118 |
|
$self->{'mounted'} = 1; |
119 |
|
|
120 |
|
$fuse_self = \$self; |
121 |
|
|
122 |
Fuse::main( |
Fuse::main( |
123 |
mountpoint=>$arg->{'mount'}, |
mountpoint=>$arg->{'mount'}, |
124 |
getattr=>\&e_getattr, |
getattr=>\&e_getattr, |
130 |
utime=>\&e_utime, |
utime=>\&e_utime, |
131 |
truncate=>\&e_truncate, |
truncate=>\&e_truncate, |
132 |
unlink=>\&e_unlink, |
unlink=>\&e_unlink, |
133 |
|
rmdir=>\&e_unlink, |
134 |
debug=>0, |
debug=>0, |
135 |
); |
); |
136 |
|
|
137 |
|
$self->{'mounted'} = 0; |
138 |
|
|
139 |
exit(0) if ($arg->{'fork'}); |
exit(0) if ($arg->{'fork'}); |
140 |
|
|
156 |
sub umount { |
sub umount { |
157 |
my $self = shift; |
my $self = shift; |
158 |
|
|
159 |
system "fusermount -u ".$self->{'mount'} || croak "umount error: $!"; |
if ($self->{'mounted'}) { |
160 |
|
system "fusermount -u ".$self->{'mount'} || croak "umount error: $!"; |
161 |
|
} |
162 |
|
|
163 |
return 1; |
return 1; |
164 |
} |
} |
165 |
|
|
166 |
#$SIG{'INT'} = sub { |
$SIG{'INT'} = sub { |
167 |
# print STDERR "umount called by SIG INT\n"; |
print STDERR "umount called by SIG INT\n"; |
168 |
# umount; |
umount; |
169 |
#}; |
}; |
170 |
|
|
171 |
sub DESTROY { |
sub DESTROY { |
172 |
my $self = shift; |
my $self = shift; |
173 |
|
return if (! $self->{'mounted'}); |
174 |
print STDERR "umount called by DESTROY\n"; |
print STDERR "umount called by DESTROY\n"; |
175 |
$self->umount; |
$self->umount; |
176 |
} |
} |
202 |
sub read_filenames { |
sub read_filenames { |
203 |
my $self = shift; |
my $self = shift; |
204 |
|
|
205 |
|
my $sth = $self->{'sth'} || die "no sth argument"; |
206 |
|
|
207 |
# create empty filesystem |
# create empty filesystem |
208 |
(%files) = ( |
(%files) = ( |
209 |
'.' => { |
'.' => { |
310 |
|
|
311 |
$sth->{'read'}->execute($id) || die $sth->{'read'}->errstr; |
$sth->{'read'}->execute($id) || die $sth->{'read'}->errstr; |
312 |
$files{$file}{cont} = $sth->{'read'}->fetchrow_array; |
$files{$file}{cont} = $sth->{'read'}->fetchrow_array; |
313 |
|
$files{$file}{ctime} = time(); |
314 |
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"; |
315 |
} |
} |
316 |
|
|
384 |
} |
} |
385 |
print "updated '$file' [",$files{$file}{id},"]\n"; |
print "updated '$file' [",$files{$file}{id},"]\n"; |
386 |
|
|
387 |
$fuse_self->{'invalidate'}->() if (ref $fuse_self->{'invalidate'}); |
$$fuse_self->{'invalidate'}->() if (ref $$fuse_self->{'invalidate'}); |
388 |
} |
} |
389 |
return 1; |
return 1; |
390 |
} |
} |
444 |
sub e_unlink { |
sub e_unlink { |
445 |
my $file = filename_fixup(shift); |
my $file = filename_fixup(shift); |
446 |
|
|
447 |
return -ENOENT() unless exists($files{$file}); |
if (exists( $dirs{$file} )) { |
448 |
|
print "unlink '$file' will re-read template names\n"; |
449 |
print "unlink '$file' will invalidate cache\n"; |
print Dumper($fuse_self); |
450 |
|
$$fuse_self->{'read_filenames'}->(); |
451 |
read_content($file,$files{$file}{id}); |
return 0; |
452 |
|
} elsif (exists( $files{$file} )) { |
453 |
|
print "unlink '$file' will invalidate cache\n"; |
454 |
|
read_content($file,$files{$file}{id}); |
455 |
|
return 0; |
456 |
|
} |
457 |
|
|
458 |
return 0; |
return -ENOENT(); |
459 |
} |
} |
460 |
1; |
1; |
461 |
__END__ |
__END__ |