From 7b8911cdd0ddf83aef97e5bc637b0ee03f96e7f9 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 16 May 2015 16:43:46 +0900 Subject: [PATCH] Cleanup --- dir.go | 4 ++-- file.go | 4 ++-- meta.go | 2 +- node.go | 37 +++++++++++++++++++++++++++++++++++++ version.go | 25 +++++++++---------------- 5 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 node.go diff --git a/dir.go b/dir.go index db2a0f1..5259f79 100644 --- a/dir.go +++ b/dir.go @@ -31,11 +31,11 @@ import ( type versionedDir struct { dirs map[string]*versionedDir files map[string]*versionedFile - node versionedNode + node *versionedNode inode uint64 } -func newVersionedDir(node versionedNode, inode uint64) *versionedDir { +func newVersionedDir(node *versionedNode, inode uint64) *versionedDir { return &versionedDir{ dirs: make(map[string]*versionedDir), files: make(map[string]*versionedFile), diff --git a/file.go b/file.go index 1af98d5..b133c8e 100644 --- a/file.go +++ b/file.go @@ -28,11 +28,11 @@ import ( ) type versionedFile struct { - node versionedNode + node *versionedNode inode uint64 } -func newVersionedFile(node versionedNode, inode uint64) *versionedFile { +func newVersionedFile(node *versionedNode, inode uint64) *versionedFile { return &versionedFile{node: node, inode: inode} } diff --git a/meta.go b/meta.go index 5e60489..e1808b1 100644 --- a/meta.go +++ b/meta.go @@ -43,7 +43,7 @@ func newVersionMetadata(path string) (*versionMetadata, error) { return meta, nil } -func (this *versionMetadata) filter(nodes map[string]versionedNode) { +func (this *versionMetadata) filter(nodes versionedNodeMap) { for _, delPath := range this.Deleted { for name, node := range nodes { if strings.HasPrefix(node.path, delPath) { diff --git a/node.go b/node.go new file mode 100644 index 0000000..80f5ac9 --- /dev/null +++ b/node.go @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 Alex Yatskov + * Author: Alex Yatskov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package main + +import "os" + +type versionedNode struct { + path string + info os.FileInfo + ver *version +} + +type versionedNodeMap map[string]*versionedNode + +func (this *versionedNode) rebasedPath() string { + return this.ver.rebasePath(this.path) +} diff --git a/version.go b/version.go index b08e6e4..738ca64 100644 --- a/version.go +++ b/version.go @@ -34,16 +34,6 @@ import ( "time" ) -type versionedNode struct { - path string - info os.FileInfo - ver *version -} - -func (this *versionedNode) rebasedPath() string { - return this.ver.rebasePath(this.path) -} - type version struct { base string parent *version @@ -82,8 +72,12 @@ func newVersion(base string, parent *version) (*version, error) { return ver, nil } -func (this *version) scanDir(path string) (map[string]versionedNode, error) { - var baseNodes map[string]versionedNode +func (this *version) newVersionedNode(path string, info os.FileInfo) *versionedNode { + return &versionedNode{path, info, this} +} + +func (this *version) scanDir(path string) (versionedNodeMap, error) { + var baseNodes versionedNodeMap if this.parent != nil { var err error @@ -95,7 +89,7 @@ func (this *version) scanDir(path string) (map[string]versionedNode, error) { this.meta.filter(baseNodes) } - ownNodes := make(map[string]versionedNode) + ownNodes := make(versionedNodeMap) { nodes, err := ioutil.ReadDir(this.rebasePath(path)) if !os.IsNotExist(err) { @@ -104,8 +98,7 @@ func (this *version) scanDir(path string) (map[string]versionedNode, error) { } for _, node := range nodes { - name := node.Name() - ownNodes[name] = versionedNode{filepath.Join(path, name), node, this} + ownNodes[node.Name()] = this.newVersionedNode(filepath.Join(path, node.Name()), node) } } @@ -152,7 +145,7 @@ func (this *version) resolve() error { } this.root = newVersionedDir( - versionedNode{"/", node, this}, + this.newVersionedNode("/", node), this.allocInode()) return this.buildVerDir(this.root)