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