Versioning kind of works
This commit is contained in:
parent
02d014ccea
commit
4e23f8f703
13
database.go
13
database.go
@ -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
|
||||||
}
|
}
|
||||||
|
15
version.go
15
version.go
@ -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,6 +94,7 @@ 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 !os.IsNotExist(err) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -107,6 +104,7 @@ func (this *version) scanDir(path string) (map[string]versionedNode, error) {
|
|||||||
ownNodes[name] = versionedNode{this.rebasePath(path, name), node}
|
ownNodes[name] = versionedNode{this.rebasePath(path, name), node}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if baseNodes == nil {
|
if baseNodes == nil {
|
||||||
return ownNodes, nil
|
return ownNodes, nil
|
||||||
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user