Versioning kind of works

This commit is contained in:
Alex Yatskov 2015-05-14 21:00:14 +09:00
parent 02d014ccea
commit 4e23f8f703
2 changed files with 20 additions and 20 deletions

View File

@ -42,23 +42,26 @@ func newDatabase(dir string) (*database, error) {
} }
func (this *database) load(dir string) error { func (this *database) load(dir string) error {
base, err := filepath.Abs(dir) var err error
this.base, err = filepath.Abs(dir)
if err != nil { if err != nil {
return err return err
} }
dirs, err := this.scan(base) dirs, err := this.scan(this.base)
if err != nil { if err != nil {
return err return err
} }
vers, err := this.versions(dirs) this.vers, err = this.versions(dirs)
if err != nil { if err != nil {
return err return err
} }
this.base = base if lastVer := this.lastVersion(); lastVer != nil {
this.vers = vers return lastVer.resolve()
}
return nil return nil
} }

View File

@ -78,10 +78,6 @@ 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
} }
@ -98,13 +94,15 @@ func (this *version) scanDir(path string) (map[string]versionedNode, error) {
ownNodes := make(map[string]versionedNode) ownNodes := make(map[string]versionedNode)
{ {
nodes, err := ioutil.ReadDir(this.rebasePath(path)) nodes, err := ioutil.ReadDir(this.rebasePath(path))
if err != nil { if !os.IsNotExist(err) {
return nil, err if err != nil {
} return nil, err
}
for _, node := range nodes { for _, node := range nodes {
name := node.Name() name := node.Name()
ownNodes[name] = versionedNode{this.rebasePath(path, name), node} ownNodes[name] = versionedNode{this.rebasePath(path, name), node}
}
} }
} }
@ -128,8 +126,7 @@ func (this *version) buildDir(path string, dir *versionedDir) error {
for name, node := range nodes { for name, node := range nodes {
if node.info.IsDir() { if node.info.IsDir() {
subDir := newVersionedDir(node, this.allocInode()) subDir := newVersionedDir(node, this.allocInode())
subDirPath := filepath.Join(path, name) if err := this.buildDir(filepath.Join(path, name), subDir); err != nil {
if err := this.buildDir(subDirPath, subDir); err != nil {
return err return err
} }
@ -142,7 +139,7 @@ func (this *version) buildDir(path string, dir *versionedDir) error {
return nil return nil
} }
func (this *version) scanFs() error { func (this *version) resolve() error {
node, err := os.Stat(this.rebasePath("/")) node, err := os.Stat(this.rebasePath("/"))
if err != nil { if err != nil {
return err return err
@ -202,11 +199,11 @@ func (this *version) Root() (fs.Node, error) {
func (this *version) dump(root *versionedDir, depth int) { func (this *version) dump(root *versionedDir, depth int) {
indent := strings.Repeat("\t", depth) indent := strings.Repeat("\t", depth)
for name, dir := range root.dirs { for name, dir := range root.dirs {
fmt.Printf("+ %s%s (%s) >\n", indent, name, dir.node.path) fmt.Printf("%s+ %s (%s)\n", indent, name, dir.node.path)
this.dump(dir, depth+1) this.dump(dir, depth+1)
} }
for name, file := range root.files { for name, file := range root.files {
fmt.Printf("- %s%s (%s)\n", indent, name, file.node.path) fmt.Printf("%s- %s (%s)\n", indent, name, file.node.path)
} }
} }