Work in progress
This commit is contained in:
parent
abe64d8a29
commit
0f0a8e29f9
74
database.go
74
database.go
@ -23,38 +23,94 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Database struct {
|
||||
base string
|
||||
versions []Version
|
||||
}
|
||||
|
||||
func NewDatabase(dir string) (*Database, error) {
|
||||
db := &Database{base: dir}
|
||||
if err := db.load(dir); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
||||
|
||||
func (this *Database) load(dir string) error {
|
||||
base, err := filepath.Abs(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
this.base = base
|
||||
|
||||
dirs, err := this.scan(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
this.version(dirs)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *Database) scan(dir string) ([]os.FileInfo, error) {
|
||||
func (this *Database) version(dirs []string) []Version {
|
||||
versions := make([]Version, 0, len(dirs))
|
||||
|
||||
// var parent *Version
|
||||
// for _, dir := range dirs {
|
||||
// base := filepath.Join(this.base, dir)
|
||||
// // timestamp := this.timestamp(dir)
|
||||
// // version := NewVersion(base, timestamp, parent)
|
||||
// // parent = version
|
||||
// }
|
||||
|
||||
return versions
|
||||
}
|
||||
|
||||
func (this *Database) scan(dir string) ([]VersionMeta, error) {
|
||||
nodes, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var dirs []os.FileInfo
|
||||
re, err := regexp.Compile(`^vfs_([0-9a-f])$`)
|
||||
|
||||
var meta []VersionMeta
|
||||
for _, node := range nodes {
|
||||
if node.IsDir() {
|
||||
dirs = append(dirs, node)
|
||||
}
|
||||
if !node.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
return dirs, nil
|
||||
matches := re.FindStringSubmatch(node.Name())
|
||||
if len(matches) < 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
func (this *Database) save(dir string) {
|
||||
timestamp, err := strconv.ParseInt(matches[1], 16, 64)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
item := VersionMeta{
|
||||
path: filepath.Join(dir, matches[0]),
|
||||
timestamp: time.Unix(timestamp, 0)}
|
||||
|
||||
meta = append(meta, item)
|
||||
}
|
||||
|
||||
return meta, nil
|
||||
}
|
||||
|
||||
func (this *Database) scanProps(path string) error {
|
||||
|
||||
}
|
||||
|
17
version.go
17
version.go
@ -26,12 +26,17 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Version struct {
|
||||
root string
|
||||
parent *Version
|
||||
version time.Time
|
||||
type VersionMeta struct {
|
||||
path string
|
||||
timestamp time.Time
|
||||
}
|
||||
|
||||
func (this *Version) NewVersion(root string, parent *Version) *Version {
|
||||
return &Version{root: root, parent: parent}
|
||||
type Version struct {
|
||||
base string
|
||||
parent *Version
|
||||
timestamp time.Time
|
||||
}
|
||||
|
||||
func NewVersion(base string, timestamp time.Time, parent *Version) *Version {
|
||||
return &Version{base, parent, timestamp}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user