Cleanup
This commit is contained in:
parent
ed1c8bc1e6
commit
0613779a78
13
database.go
13
database.go
@ -36,10 +36,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var inodeCnt uint64
|
||||||
|
|
||||||
type database struct {
|
type database struct {
|
||||||
base string
|
base string
|
||||||
vers []*version
|
vers []*version
|
||||||
inodeCnt uint64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDatabase(dir string) (*database, error) {
|
func newDatabase(dir string) (*database, error) {
|
||||||
@ -94,7 +95,7 @@ func (this *database) buildVersions(base string, names []string) ([]*version, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ver, err := newVersion(path.Join(base, name), timestamp, this, parent)
|
ver, err := newVersion(path.Join(base, name), timestamp, parent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -152,10 +153,6 @@ func (this *database) Root() (fs.Node, error) {
|
|||||||
return this.lastVersion().root, nil
|
return this.lastVersion().root, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *database) AllocInode() uint64 {
|
|
||||||
return atomic.AddUint64(&this.inodeCnt, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *database) buildVerName(timestamp time.Time) string {
|
func (this *database) buildVerName(timestamp time.Time) string {
|
||||||
return fmt.Sprintf("ver_%.16x", timestamp.Unix())
|
return fmt.Sprintf("ver_%.16x", timestamp.Unix())
|
||||||
}
|
}
|
||||||
@ -178,3 +175,7 @@ func (this *database) parseVerName(name string) (time.Time, error) {
|
|||||||
|
|
||||||
return time.Unix(timestamp, 0), nil
|
return time.Unix(timestamp, 0), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func allocInode() uint64 {
|
||||||
|
return atomic.AddUint64(&inodeCnt, 1)
|
||||||
|
}
|
||||||
|
2
dir.go
2
dir.go
@ -43,7 +43,7 @@ func newVersionedDir(node *versionedNode, parent *versionedDir) *versionedDir {
|
|||||||
dirs: make(map[string]*versionedDir),
|
dirs: make(map[string]*versionedDir),
|
||||||
files: make(map[string]*versionedFile),
|
files: make(map[string]*versionedFile),
|
||||||
node: node,
|
node: node,
|
||||||
inode: node.ver.inodeAloc.AllocInode(),
|
inode: allocInode(),
|
||||||
parent: parent}
|
parent: parent}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
file.go
2
file.go
@ -40,7 +40,7 @@ type versionedFile struct {
|
|||||||
func newVersionedFile(node *versionedNode, parent *versionedDir) *versionedFile {
|
func newVersionedFile(node *versionedNode, parent *versionedDir) *versionedFile {
|
||||||
return &versionedFile{
|
return &versionedFile{
|
||||||
node: node,
|
node: node,
|
||||||
inode: node.ver.inodeAloc.AllocInode(),
|
inode: allocInode(),
|
||||||
parent: parent}
|
parent: parent}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
version.go
10
version.go
@ -39,14 +39,9 @@ type version struct {
|
|||||||
timestamp time.Time
|
timestamp time.Time
|
||||||
meta *versionMetadata
|
meta *versionMetadata
|
||||||
root *versionedDir
|
root *versionedDir
|
||||||
inodeAloc InodeAllocator
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type InodeAllocator interface {
|
func newVersion(base string, timestamp time.Time, parent *version) (*version, error) {
|
||||||
AllocInode() uint64
|
|
||||||
}
|
|
||||||
|
|
||||||
func newVersion(base string, timestamp time.Time, allocator InodeAllocator, parent *version) (*version, error) {
|
|
||||||
meta, err := newVersionMetadata(filepath.Join(base, "meta.json"))
|
meta, err := newVersionMetadata(filepath.Join(base, "meta.json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -56,8 +51,7 @@ func newVersion(base string, timestamp time.Time, allocator InodeAllocator, pare
|
|||||||
base: base,
|
base: base,
|
||||||
parent: parent,
|
parent: parent,
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
meta: meta,
|
meta: meta}
|
||||||
inodeAloc: allocator}
|
|
||||||
|
|
||||||
return ver, nil
|
return ver, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user