This commit is contained in:
Alex Yatskov 2015-05-16 16:43:46 +09:00
parent 3ab3960a6d
commit 7b8911cdd0
5 changed files with 51 additions and 21 deletions

4
dir.go
View File

@ -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),

View File

@ -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}
}

View File

@ -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) {

37
node.go Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2015 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* 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)
}

View File

@ -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)