diff --git a/database.go b/database.go index 9111505..36457d9 100644 --- a/database.go +++ b/database.go @@ -23,6 +23,7 @@ package main import ( + "bazil.org/fuse/fs" "io/ioutil" "path/filepath" ) @@ -41,6 +42,10 @@ func newDatabase(dir string) (*database, error) { return db, nil } +func (this *database) Root() (fs.Node, error) { + return this.lastVersion(), nil +} + func (this *database) load(dir string) error { base, err := filepath.Abs(dir) if err != nil { @@ -52,7 +57,7 @@ func (this *database) load(dir string) error { return err } - vers, err := this.version(dirs) + vers, err := this.versions(dirs) if err != nil { return err } @@ -67,7 +72,7 @@ func (this *database) save() error { return nil } -func (this *database) version(dirs []string) ([]*version, error) { +func (this *database) versions(dirs []string) ([]*version, error) { var vers []*version var parent *version @@ -84,6 +89,15 @@ func (this *database) version(dirs []string) ([]*version, error) { 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) { nodes, err := ioutil.ReadDir(dir) if err != nil { diff --git a/version.go b/version.go index fb71c7a..260ee6e 100644 --- a/version.go +++ b/version.go @@ -23,8 +23,11 @@ package main import ( + "bazil.org/fuse" + "bazil.org/fuse/fs" "encoding/json" "fmt" + "golang.org/x/net/context" "io/ioutil" "os" "path/filepath" @@ -72,6 +75,40 @@ func newVersion(base string, parent *version) (*version, error) { 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 { path := this.metadataPath() if _, err := os.Stat(path); os.IsNotExist(err) {