Cleanup
This commit is contained in:
parent
7e1207065e
commit
f28add5773
16
dir.go
16
dir.go
@ -38,32 +38,30 @@ type versionedDir struct {
|
||||
parent *versionedDir
|
||||
}
|
||||
|
||||
func newVersionedDir(node *versionedNode, inode uint64, parent *versionedDir) *versionedDir {
|
||||
func newVersionedDir(node *versionedNode, parent *versionedDir) *versionedDir {
|
||||
return &versionedDir{
|
||||
dirs: make(map[string]*versionedDir),
|
||||
files: make(map[string]*versionedFile),
|
||||
node: node,
|
||||
inode: inode,
|
||||
inode: node.ver.inodeAloc.AllocInode(),
|
||||
parent: parent}
|
||||
}
|
||||
|
||||
func (this *versionedDir) createDir(name string) (*versionedDir, error) {
|
||||
childPath := path.Join(this.node.path, name)
|
||||
childPathFull := this.node.ver.rebasePath(childPath)
|
||||
|
||||
if err := os.Mkdir(childPathFull, 0755); err != nil {
|
||||
if err := os.Mkdir(this.node.ver.rebasePath(childPath), 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info, err := os.Stat(childPathFull)
|
||||
node, err := newVersionedNode(childPath, this.node.ver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
node := &versionedNode{childPath, info, this.node.ver}
|
||||
dir := newVersionedDir(node, this.node.ver.inodeAloc.AllocInode(), this)
|
||||
|
||||
dir := newVersionedDir(node, this)
|
||||
this.dirs[name] = dir
|
||||
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
@ -83,7 +81,7 @@ func (this *versionedDir) createFile(name string, flags int) (*versionedFile, er
|
||||
}
|
||||
|
||||
node := &versionedNode{childPath, info, this.node.ver}
|
||||
file := newVersionedFile(node, this.node.ver.inodeAloc.AllocInode(), this)
|
||||
file := newVersionedFile(node, this)
|
||||
|
||||
this.files[name] = file
|
||||
return file, nil
|
||||
|
4
file.go
4
file.go
@ -35,10 +35,10 @@ type versionedFile struct {
|
||||
parent *versionedDir
|
||||
}
|
||||
|
||||
func newVersionedFile(node *versionedNode, inode uint64, parent *versionedDir) *versionedFile {
|
||||
func newVersionedFile(node *versionedNode, parent *versionedDir) *versionedFile {
|
||||
return &versionedFile{
|
||||
node: node,
|
||||
inode: inode,
|
||||
inode: node.ver.inodeAloc.AllocInode(),
|
||||
parent: parent}
|
||||
}
|
||||
|
||||
|
13
node.go
13
node.go
@ -38,6 +38,19 @@ type versionedNode struct {
|
||||
|
||||
type versionedNodeMap map[string]*versionedNode
|
||||
|
||||
func newVersionedNode(path string, ver *version) (*versionedNode, error) {
|
||||
info, err := os.Stat(ver.rebasePath(path))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newVersionedNodeStat(path, ver, info), nil
|
||||
}
|
||||
|
||||
func newVersionedNodeStat(path string, ver *version, info os.FileInfo) *versionedNode {
|
||||
return &versionedNode{path, info, ver}
|
||||
}
|
||||
|
||||
func (this *versionedNode) rebasedPath() string {
|
||||
return this.ver.rebasePath(this.path)
|
||||
}
|
||||
|
44
version.go
44
version.go
@ -63,22 +63,19 @@ func newVersion(base string, allocator InodeAllocator, parent *version) (*versio
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ver := &version{
|
||||
base: base,
|
||||
parent: parent,
|
||||
timestamp: time.Unix(timeval, 0),
|
||||
inodeAloc: allocator}
|
||||
|
||||
ver.meta, err = newVersionMetadata(ver.metadataPath())
|
||||
meta, err := newVersionMetadata(filepath.Join(base, "meta.json"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ver, nil
|
||||
}
|
||||
ver := &version{
|
||||
base: base,
|
||||
parent: parent,
|
||||
timestamp: time.Unix(timeval, 0),
|
||||
meta: meta,
|
||||
inodeAloc: allocator}
|
||||
|
||||
func (this *version) newVersionedNode(path string, info os.FileInfo) *versionedNode {
|
||||
return &versionedNode{path, info, this}
|
||||
return ver, nil
|
||||
}
|
||||
|
||||
func (this *version) scanDir(path string) (versionedNodeMap, error) {
|
||||
@ -96,14 +93,16 @@ func (this *version) scanDir(path string) (versionedNodeMap, error) {
|
||||
|
||||
ownNodes := make(versionedNodeMap)
|
||||
{
|
||||
nodes, err := ioutil.ReadDir(this.rebasePath(path))
|
||||
infos, err := ioutil.ReadDir(this.rebasePath(path))
|
||||
if !os.IsNotExist(err) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, node := range nodes {
|
||||
ownNodes[node.Name()] = this.newVersionedNode(filepath.Join(path, node.Name()), node)
|
||||
for _, info := range infos {
|
||||
childName := info.Name()
|
||||
childPath := filepath.Join(path, childName)
|
||||
ownNodes[childName] = newVersionedNodeStat(childPath, this, info)
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,14 +128,14 @@ func (this *version) buildVerDir(dir *versionedDir) error {
|
||||
|
||||
for name, node := range nodes {
|
||||
if node.info.IsDir() {
|
||||
subDir := newVersionedDir(node, this.inodeAloc.AllocInode(), dir)
|
||||
subDir := newVersionedDir(node, dir)
|
||||
if err := this.buildVerDir(subDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dir.dirs[name] = subDir
|
||||
} else {
|
||||
dir.files[name] = newVersionedFile(node, this.inodeAloc.AllocInode(), dir)
|
||||
dir.files[name] = newVersionedFile(node, dir)
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,17 +143,18 @@ func (this *version) buildVerDir(dir *versionedDir) error {
|
||||
}
|
||||
|
||||
func (this *version) resolve() error {
|
||||
node, err := os.Stat(this.rebasePath("/"))
|
||||
node, err := newVersionedNode("/", this)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
this.root = newVersionedDir(
|
||||
this.newVersionedNode("/", node),
|
||||
this.inodeAloc.AllocInode(),
|
||||
nil)
|
||||
root := newVersionedDir(node, nil)
|
||||
if err = this.buildVerDir(root); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return this.buildVerDir(this.root)
|
||||
this.root = root
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *version) metadataPath() string {
|
||||
|
Loading…
Reference in New Issue
Block a user