Work in progress
This commit is contained in:
parent
f82f0e612f
commit
115c46142c
47
version.go
47
version.go
@ -37,17 +37,17 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type metadata struct {
|
type versionMetadata struct {
|
||||||
Deleted []string
|
Deleted []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type file struct {
|
type versionedFile struct {
|
||||||
info os.FileInfo
|
info os.FileInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
type directory struct {
|
type versionedDir struct {
|
||||||
dirs map[string]directory
|
dirs map[string]versionedDir
|
||||||
files map[string]file
|
files map[string]versionedFile
|
||||||
info os.FileInfo
|
info os.FileInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +55,8 @@ type version struct {
|
|||||||
base string
|
base string
|
||||||
parent *version
|
parent *version
|
||||||
timestamp time.Time
|
timestamp time.Time
|
||||||
meta metadata
|
meta versionMetadata
|
||||||
root directory
|
root versionedDir
|
||||||
}
|
}
|
||||||
|
|
||||||
func newVersion(base string, parent *version) (*version, error) {
|
func newVersion(base string, parent *version) (*version, error) {
|
||||||
@ -94,7 +94,8 @@ func newVersion(base string, parent *version) (*version, error) {
|
|||||||
func (this *version) scanDir(path string) (map[string]os.FileInfo, error) {
|
func (this *version) scanDir(path string) (map[string]os.FileInfo, error) {
|
||||||
ownNodes := make(map[string]os.FileInfo)
|
ownNodes := make(map[string]os.FileInfo)
|
||||||
{
|
{
|
||||||
nodes, err := ioutil.ReadDir(this.rebasePath(path))
|
fullPath := filepath.Join(this.rootPath(), path)
|
||||||
|
nodes, err := ioutil.ReadDir(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -113,23 +114,29 @@ func (this *version) scanDir(path string) (map[string]os.FileInfo, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for ownName, ownNode := range ownNodes {
|
for ownName, ownInfo := range ownNodes {
|
||||||
baseNodes[ownName] = ownNode
|
baseNodes[ownName] = ownInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseNodes, nil
|
return baseNodes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *version) buildDir(path string, dir *directory) error {
|
func (this *version) buildDir(path string, dir *versionedDir) error {
|
||||||
nodes, err := ioutil.ReadDir(path)
|
nodes, err := this.scanDir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, node := range nodes {
|
for name, info := range nodes {
|
||||||
if node.IsDir() {
|
if info.IsDir() {
|
||||||
|
subDir := versionedDir{info: info}
|
||||||
|
subDirPath := filepath.Join(path, name)
|
||||||
|
if err := this.buildDir(subDirPath, &subDir); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
dir.dirs[name] = subDir
|
||||||
} else {
|
} else {
|
||||||
|
dir.files[name] = versionedFile{info: info}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,6 +144,12 @@ func (this *version) buildDir(path string, dir *directory) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *version) scanFs() error {
|
func (this *version) scanFs() error {
|
||||||
|
rootNode, err := os.Stat(this.rootPath())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
this.root = versionedDir{info: rootNode}
|
||||||
return this.buildDir(this.rootPath(), &this.root)
|
return this.buildDir(this.rootPath(), &this.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,10 +188,6 @@ 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) {
|
// func (this *version) Attr(a *fuse.Attr) {
|
||||||
// // type Attr struct {
|
// // type Attr struct {
|
||||||
// // Inode uint64 // inode number
|
// // Inode uint64 // inode number
|
||||||
|
Loading…
Reference in New Issue
Block a user