better support for zero-sized files
[Fuse-DBI] / DBI.pm
diff --git a/DBI.pm b/DBI.pm
index 3b36596..7c07132 100755 (executable)
--- a/DBI.pm
+++ b/DBI.pm
@@ -249,9 +249,11 @@ sub umount {
        my $self = shift;
 
        if ($self->{'mount'} && $self->is_mounted) {
-               system "( fusermount -u ".$self->{'mount'}." 2>&1 ) >/dev/null" ||
+               system "( fusermount -u ".$self->{'mount'}." 2>&1 ) >/dev/null";
+               if ($self->is_mounted) {
                        system "sudo umount ".$self->{'mount'} ||
                        return 0;
+               }
                return 1;
        }
 
@@ -371,7 +373,7 @@ sub e_getattr {
        $file =~ s,^/,,;
        $file = '.' unless length($file);
        return -ENOENT() unless exists($files{$file});
-       my ($size) = $files{$file}{size} || BLOCK;
+       my ($size) = $files{$file}{size} || 0;
        my ($dev, $ino, $rdev, $blocks, $gid, $uid, $nlink, $blksize) = (0,0,0,int(($size+BLOCK-1)/BLOCK),0,0,1,BLOCK);
        my ($atime, $ctime, $mtime);
        $atime = $ctime = $mtime = $files{$file}{ctime} || $ctime_start;
@@ -380,7 +382,7 @@ sub e_getattr {
 
        # 2 possible types of return values:
        #return -ENOENT(); # or any other error you care to
-       print "getattr($file) ",join(",",($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)),"\n";
+       #print "getattr($file) ",join(",",($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)),"\n";
        return ($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks);
 }
 
@@ -430,6 +432,7 @@ sub e_open {
 
        read_content($file,$files{$file}{id}) unless exists($files{$file}{cont});
 
+       $files{$file}{cont} ||= '';
        print "open '$file' ",length($files{$file}{cont})," bytes\n";
        return 0;
 }
@@ -562,7 +565,7 @@ sub e_statfs {
 
        my @ret = (255, $inodes, 1, $size, $size-1, BLOCK);
 
-       print "statfs: ",join(",",@ret),"\n";
+       #print "statfs: ",join(",",@ret),"\n";
 
        return @ret;
 }