More work on mounting interface

This commit is contained in:
Alex Yatskov 2015-05-10 19:41:15 +09:00
parent 903bc4a145
commit df0657f88c
2 changed files with 53 additions and 2 deletions

View File

@ -23,6 +23,7 @@
package main package main
import ( import (
"bazil.org/fuse/fs"
"io/ioutil" "io/ioutil"
"path/filepath" "path/filepath"
) )
@ -41,6 +42,10 @@ func newDatabase(dir string) (*database, error) {
return db, nil return db, nil
} }
func (this *database) Root() (fs.Node, error) {
return this.lastVersion(), nil
}
func (this *database) load(dir string) error { func (this *database) load(dir string) error {
base, err := filepath.Abs(dir) base, err := filepath.Abs(dir)
if err != nil { if err != nil {
@ -52,7 +57,7 @@ func (this *database) load(dir string) error {
return err return err
} }
vers, err := this.version(dirs) vers, err := this.versions(dirs)
if err != nil { if err != nil {
return err return err
} }
@ -67,7 +72,7 @@ func (this *database) save() error {
return nil return nil
} }
func (this *database) version(dirs []string) ([]*version, error) { func (this *database) versions(dirs []string) ([]*version, error) {
var vers []*version var vers []*version
var parent *version var parent *version
@ -84,6 +89,15 @@ func (this *database) version(dirs []string) ([]*version, error) {
return vers, nil return vers, nil
} }
func (this *database) lastVersion() *version {
count := len(this.vers)
if count == 0 {
return nil
}
return this.vers[count-1]
}
func (this *database) scan(dir string) ([]string, error) { func (this *database) scan(dir string) ([]string, error) {
nodes, err := ioutil.ReadDir(dir) nodes, err := ioutil.ReadDir(dir)
if err != nil { if err != nil {

View File

@ -23,8 +23,11 @@
package main package main
import ( import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
"encoding/json" "encoding/json"
"fmt" "fmt"
"golang.org/x/net/context"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -72,6 +75,40 @@ func newVersion(base string, parent *version) (*version, error) {
return ver, nil return ver, nil
} }
func (this *version) Attr(a *fuse.Attr) {
// type Attr struct {
// Inode uint64 // inode number
// Size uint64 // size in bytes
// Blocks uint64 // size in blocks
// Atime time.Time // time of last access
// Mtime time.Time // time of last modification
// Ctime time.Time // time of last inode change
// Crtime time.Time // time of creation (OS X only)
// Mode os.FileMode // file mode
// Nlink uint32 // number of links
// Uid uint32 // owner uid
// Gid uint32 // group gid
// Rdev uint32 // device numbers
// Flags uint32 // chflags(2) flags (OS X only)
a.Inode = 1
a.Mode = os.ModeDir | 0755
}
func (this *version) Lookup(ctx context.Context, name string) (fs.Node, error) {
// if name == "hello" {
// return File{}, nil
// }
return nil, fuse.ENOENT
}
func (this *version) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
var dirDirs = []fuse.Dirent{
{Inode: 2, Name: "hello", Type: fuse.DT_File},
}
return dirDirs, nil
}
func (this *version) loadMetadata() error { func (this *version) loadMetadata() error {
path := this.metadataPath() path := this.metadataPath()
if _, err := os.Stat(path); os.IsNotExist(err) { if _, err := os.Stat(path); os.IsNotExist(err) {