Work in progress
This commit is contained in:
parent
d6304ebd87
commit
a6e310e46e
23
database.go
23
database.go
@ -58,12 +58,12 @@ func (this *database) load(dir string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dirs, err := this.scan(this.base)
|
names, err := this.scan(this.base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
this.vers, err = this.version(dirs)
|
this.vers, err = this.version(this.base, names)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -79,17 +79,17 @@ func (this *database) save() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *database) version(dirs []string) ([]*version, error) {
|
func (this *database) version(base string, names []string) ([]*version, error) {
|
||||||
var vers []*version
|
var vers []*version
|
||||||
|
|
||||||
var parent *version
|
var parent *version
|
||||||
for _, dir := range dirs {
|
for _, name := range names {
|
||||||
time, err := this.parseVerName(path.Base(dir))
|
timestamp, err := this.parseVerName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ver, err := newVersion(dir, time, this, parent)
|
ver, err := newVersion(path.Join(base, name), timestamp, this, parent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -116,14 +116,15 @@ func (this *database) scan(dir string) ([]string, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var dirs []string
|
var names []string
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
if node.IsDir() {
|
if node.IsDir() {
|
||||||
dirs = append(dirs, filepath.Join(dir, node.Name()))
|
names = append(names, node.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dirs, nil
|
names = append(names, this.buildVerName(time.Now()))
|
||||||
|
return names, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *database) Root() (fs.Node, error) {
|
func (this *database) Root() (fs.Node, error) {
|
||||||
@ -135,11 +136,11 @@ func (this *database) AllocInode() uint64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *database) buildVerName(timestamp time.Time) string {
|
func (this *database) buildVerName(timestamp time.Time) string {
|
||||||
return fmt.Sprintf("%x", timestamp.Unix())
|
return fmt.Sprintf("vfs_%x", timestamp.Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *database) parseVerName(name string) (time.Time, error) {
|
func (this *database) parseVerName(name string) (time.Time, error) {
|
||||||
re, err := regexp.Compile(`vfs_([0-9a-f])$`)
|
re, err := regexp.Compile(`vfs_([0-9a-f]+)$`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return time.Unix(0, 0), err
|
return time.Unix(0, 0), err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user