Work in progress

This commit is contained in:
Alex Yatskov 2015-05-12 17:20:13 +09:00
parent df0657f88c
commit f82f0e612f

View File

@ -23,11 +23,12 @@
package main package main
import ( import (
"bazil.org/fuse" // "bazil.org/fuse"
"bazil.org/fuse/fs" // "bazil.org/fuse/fs"
// "golang.org/x/net/context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"golang.org/x/net/context"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -40,11 +41,22 @@ type metadata struct {
Deleted []string 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 { type version struct {
base string base string
parent *version parent *version
timestamp time.Time timestamp time.Time
meta metadata meta metadata
root directory
} }
func newVersion(base string, parent *version) (*version, error) { func newVersion(base string, parent *version) (*version, error) {
@ -72,41 +84,60 @@ func newVersion(base string, parent *version) (*version, error) {
return nil, err return nil, err
} }
if err := ver.scanFs(); err != nil {
return nil, err
}
return ver, nil return ver, nil
} }
func (this *version) Attr(a *fuse.Attr) { func (this *version) scanDir(path string) (map[string]os.FileInfo, error) {
// type Attr struct { ownNodes := make(map[string]os.FileInfo)
// Inode uint64 // inode number {
// Size uint64 // size in bytes nodes, err := ioutil.ReadDir(this.rebasePath(path))
// Blocks uint64 // size in blocks if err != nil {
// Atime time.Time // time of last access return nil, err
// 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) { for _, node := range nodes {
// if name == "hello" { ownNodes[node.Name()] = node
// return File{}, nil }
// }
return nil, fuse.ENOENT
} }
func (this *version) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { if this.parent == nil {
var dirDirs = []fuse.Dirent{ return ownNodes, nil
{Inode: 2, Name: "hello", Type: fuse.DT_File},
} }
return dirDirs, 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 { func (this *version) loadMetadata() error {
@ -143,3 +174,41 @@ func (this *version) metadataPath() string {
func (this *version) rootPath() string { func (this *version) rootPath() string {
return filepath.Join(this.base, "root") 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
// }