/[fuse_dbi]/fuse-couchdb/DBI.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /fuse-couchdb/DBI.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 62 by dpavlin, Wed Aug 2 21:53:30 2006 UTC revision 64 by dpavlin, Sun Nov 26 22:29:23 2006 UTC
# Line 144  sub fuse_module_loaded; Line 144  sub fuse_module_loaded;
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 = {};
# Line 195  sub mount { Line 197  sub mount {
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;
# Line 212  sub mount { Line 214  sub mount {
214                  }                  }
215          }          }
216    
217          $fuse_self = \$self;          $fuse_self = $self;
218    
219          Fuse::main(          Fuse::main(
220                  mountpoint=>$arg->{'mount'},                  mountpoint=>$arg->{'mount'},
# Line 226  sub mount { Line 228  sub 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'});
# Line 277  sub umount { Line 279  sub umount {
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;
# Line 288  sub umount { Line 291  sub umount {
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  };  };
# Line 444  sub read_content { Line 447  sub read_content {
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;
# Line 517  sub update_db { Line 520  sub update_db {
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)) {
# Line 536  sub update_db { Line 544  sub update_db {
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  }  }
# Line 619  sub e_unlink { Line 627  sub e_unlink {
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";

Legend:
Removed from v.62  
changed lines
  Added in v.64

  ViewVC Help
Powered by ViewVC 1.1.26