/[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 12 by dpavlin, Sun Aug 29 19:16:01 2004 UTC revision 18 by dpavlin, Sun Sep 5 16:59:41 2004 UTC
# Line 14  use Proc::Simple; Line 14  use Proc::Simple;
14  use Data::Dumper;  use Data::Dumper;
15    
16    
17  our $VERSION = '0.01';  our $VERSION = '0.02';
18    
19  =head1 NAME  =head1 NAME
20    
# Line 86  sub mount { Line 86  sub mount {
86          $dbh = DBI->connect($arg->{'dsn'},$arg->{'user'},$arg->{'password'}, { AutoCommit => 0 }) || die $DBI::errstr;          $dbh = DBI->connect($arg->{'dsn'},$arg->{'user'},$arg->{'password'}, { AutoCommit => 0 }) || die $DBI::errstr;
87    
88          print "start transaction\n";          print "start transaction\n";
89          #$dbh->begin_work || die $dbh->errstr;          $dbh->begin_work || die $dbh->errstr;
90    
91          $sth->{filenames} = $dbh->prepare($arg->{'filenames'}) || die $dbh->errstr();          $sth->{filenames} = $dbh->prepare($arg->{'filenames'}) || die $dbh->errstr();
92    
# Line 235  sub e_getdir { Line 235  sub e_getdir {
235          # return as many text filenames as you like, followed by the retval.          # return as many text filenames as you like, followed by the retval.
236          print((scalar keys %files)." files total\n");          print((scalar keys %files)." files total\n");
237          my %out;          my %out;
238          foreach (keys %files) {          foreach my $f (sort keys %files) {
                 my $f = $_;  
                 $f =~ s/^\E$dirname\Q//;  
                 $f =~ s/^\///;  
239                  if ($dirname) {                  if ($dirname) {
240                          $out{$f}++ if (/^\E$dirname\Q/ && $f =~ /^[^\/]+$/);                          if ($f =~ s/^\E$dirname\Q\///) {
241                                    $out{$f}++ if ($f =~ /^[^\/]+$/);
242                            }
243                  } else {                  } else {
244                          $out{$f}++ if ($f =~ /^[^\/]+$/);                          $out{$f}++ if ($f =~ /^[^\/]+$/);
245                  }                  }
# Line 249  sub e_getdir { Line 248  sub e_getdir {
248                  $out{'no files? bug?'}++;                  $out{'no files? bug?'}++;
249          }          }
250          print scalar keys %out," files in dir '$dirname'\n";          print scalar keys %out," files in dir '$dirname'\n";
251            print "## ",join(" ",keys %out),"\n";
252          return (keys %out),0;          return (keys %out),0;
253  }  }
254    
# Line 324  sub update_db { Line 324  sub update_db {
324    
325  sub e_write {  sub e_write {
326          my $file = filename_fixup(shift);          my $file = filename_fixup(shift);
327          my ($buf_len,$off) = @_;          my ($buffer,$off) = @_;
328    
329          return -ENOENT() unless exists($files{$file});          return -ENOENT() unless exists($files{$file});
330    
331          my $len = length($files{$file}{cont});          my $cont = $files{$file}{cont};
332            my $len = length($cont);
333    
334          print "write '$file' [$len bytes] offset $off length\n";          print "write '$file' [$len bytes] offset $off length ",length($buffer),"\n";
335    
336          $files{$file}{cont} =          $files{$file}{cont} = "";
337                  substr($files{$file}{cont},0,$off) .  
338                  $buf_len .          $files{$file}{cont} .= substr($cont,0,$off) if ($off > 0);
339                  substr($files{$file}{cont},$off+length($buf_len));          $files{$file}{cont} .= $buffer;
340            $files{$file}{cont} .= substr($cont,-($off+length($buffer))) if ($off+length($buffer) > $len);
341    
342            $files{$file}{size} = length($files{$file}{cont});
343    
344          if (! update_db($file)) {          if (! update_db($file)) {
345                  return -ENOSYS();                  return -ENOSYS();
346          } else {          } else {
347                  return length($buf_len);                  return length($buffer);
348          }          }
349  }  }
350    
# Line 348  sub e_truncate { Line 352  sub e_truncate {
352          my $file = filename_fixup(shift);          my $file = filename_fixup(shift);
353          my $size = shift;          my $size = shift;
354    
355            print "truncate to $size\n";
356    
357          $files{$file}{cont} = substr($files{$file}{cont},0,$size);          $files{$file}{cont} = substr($files{$file}{cont},0,$size);
358            $files{$file}{size} = $size;
359          return 0          return 0
360  };  };
361    

Legend:
Removed from v.12  
changed lines
  Added in v.18

  ViewVC Help
Powered by ViewVC 1.1.26