Work in progress

This commit is contained in:
Alex Yatskov 2015-05-09 22:48:08 +09:00
parent abe64d8a29
commit 0f0a8e29f9
3 changed files with 77 additions and 15 deletions

View File

@ -23,38 +23,94 @@
package main package main
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"os" "path/filepath"
"regexp"
"strconv"
"strings"
"time"
) )
type Database struct { 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 { 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) dirs, err := this.scan(dir)
if err != nil { if err != nil {
return err 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) nodes, err := ioutil.ReadDir(dir)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var dirs []os.FileInfo re, err := regexp.Compile(`^vfs_([0-9a-f])$`)
var meta []VersionMeta
for _, node := range nodes { for _, node := range nodes {
if node.IsDir() { if !node.IsDir() {
dirs = append(dirs, node) 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 {
} }

View File

@ -26,12 +26,17 @@ import (
"time" "time"
) )
type Version struct { type VersionMeta struct {
root string path string
parent *Version timestamp time.Time
version time.Time
} }
func (this *Version) NewVersion(root string, parent *Version) *Version { type Version struct {
return &Version{root: root, parent: parent} base string
parent *Version
timestamp time.Time
}
func NewVersion(base string, timestamp time.Time, parent *Version) *Version {
return &Version{base, parent, timestamp}
} }

3
vfs.go
View File

@ -23,5 +23,6 @@
package main package main
func main() { func main() {
var db Database
db.load("fs")
} }