diff --git a/version.go b/version.go index 260ee6e..c72d908 100644 --- a/version.go +++ b/version.go @@ -23,11 +23,12 @@ package main import ( - "bazil.org/fuse" - "bazil.org/fuse/fs" + // "bazil.org/fuse" + // "bazil.org/fuse/fs" + // "golang.org/x/net/context" + "encoding/json" "fmt" - "golang.org/x/net/context" "io/ioutil" "os" "path/filepath" @@ -40,11 +41,22 @@ type metadata struct { Deleted []string } +type file struct { + info os.FileInfo +} + +type directory struct { + dirs map[string]directory + files map[string]file + info os.FileInfo +} + type version struct { base string parent *version timestamp time.Time meta metadata + root directory } func newVersion(base string, parent *version) (*version, error) { @@ -72,41 +84,60 @@ func newVersion(base string, parent *version) (*version, error) { return nil, err } + if err := ver.scanFs(); err != nil { + return nil, err + } + 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) scanDir(path string) (map[string]os.FileInfo, error) { + ownNodes := make(map[string]os.FileInfo) + { + nodes, err := ioutil.ReadDir(this.rebasePath(path)) + if err != nil { + return nil, err + } -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}, + for _, node := range nodes { + ownNodes[node.Name()] = node + } } - return dirDirs, nil + if this.parent == nil { + return ownNodes, nil + } + + baseNodes, err := this.parent.scanDir(path) + if err != nil { + return nil, err + } + + for ownName, ownNode := range ownNodes { + baseNodes[ownName] = ownNode + } + + return baseNodes, nil +} + +func (this *version) buildDir(path string, dir *directory) error { + nodes, err := ioutil.ReadDir(path) + if err != nil { + return err + } + + for _, node := range nodes { + if node.IsDir() { + + } else { + } + } + + return nil +} + +func (this *version) scanFs() error { + return this.buildDir(this.rootPath(), &this.root) } func (this *version) loadMetadata() error { @@ -143,3 +174,41 @@ func (this *version) metadataPath() string { func (this *version) rootPath() string { return filepath.Join(this.base, "root") } + +func (this *version) rebasePath(path string) string { + return filepath.Join(this.rootPath(), path) +} + +// 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 +// }