Work on deleting files
This commit is contained in:
parent
2ee01b3c2d
commit
ed108335ac
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"deleted": ["/cliche"]
|
"deleted": ["/test_dir/poopy"]
|
||||||
}
|
}
|
||||||
|
11
meta.go
11
meta.go
@ -26,7 +26,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type versionMetadata struct {
|
type versionMetadata struct {
|
||||||
@ -43,11 +43,12 @@ func newVersionMetadata(path string) (*versionMetadata, error) {
|
|||||||
return meta, nil
|
return meta, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *versionMetadata) filter(base string, nodes map[string]versionedNode) {
|
func (this *versionMetadata) filter(nodes map[string]versionedNode) {
|
||||||
for _, delPath := range this.Deleted {
|
for _, delPath := range this.Deleted {
|
||||||
dir, file := filepath.Split(delPath)
|
for name, node := range nodes {
|
||||||
if dir == base {
|
if strings.HasPrefix(node.path, delPath) {
|
||||||
delete(nodes, file)
|
delete(nodes, name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
version.go
23
version.go
@ -37,6 +37,11 @@ import (
|
|||||||
type versionedNode struct {
|
type versionedNode struct {
|
||||||
path string
|
path string
|
||||||
info os.FileInfo
|
info os.FileInfo
|
||||||
|
ver *version
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *versionedNode) rebasedPath() string {
|
||||||
|
return this.ver.rebasePath(this.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
type version struct {
|
type version struct {
|
||||||
@ -87,7 +92,7 @@ func (this *version) scanDir(path string) (map[string]versionedNode, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
this.meta.filter(path, baseNodes)
|
this.meta.filter(baseNodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
ownNodes := make(map[string]versionedNode)
|
ownNodes := make(map[string]versionedNode)
|
||||||
@ -100,11 +105,11 @@ func (this *version) scanDir(path string) (map[string]versionedNode, error) {
|
|||||||
|
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
name := node.Name()
|
name := node.Name()
|
||||||
ownNodes[name] = versionedNode{this.rebasePath(path, name), node}
|
ownNodes[name] = versionedNode{filepath.Join(path, name), node, this}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.meta.filter(path, ownNodes)
|
this.meta.filter(ownNodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
if baseNodes == nil {
|
if baseNodes == nil {
|
||||||
@ -118,7 +123,7 @@ func (this *version) scanDir(path string) (map[string]versionedNode, error) {
|
|||||||
return baseNodes, nil
|
return baseNodes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *version) buildDir(path string, dir *versionedDir) error {
|
func (this *version) buildVerDir(path string, dir *versionedDir) error {
|
||||||
nodes, err := this.scanDir(path)
|
nodes, err := this.scanDir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -127,7 +132,7 @@ func (this *version) buildDir(path string, dir *versionedDir) error {
|
|||||||
for name, node := range nodes {
|
for name, node := range nodes {
|
||||||
if node.info.IsDir() {
|
if node.info.IsDir() {
|
||||||
subDir := newVersionedDir(node, this.allocInode())
|
subDir := newVersionedDir(node, this.allocInode())
|
||||||
if err := this.buildDir(filepath.Join(path, name), subDir); err != nil {
|
if err := this.buildVerDir(filepath.Join(path, name), subDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,10 +152,10 @@ func (this *version) resolve() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.root = newVersionedDir(
|
this.root = newVersionedDir(
|
||||||
versionedNode{"/", node},
|
versionedNode{"/", node, this},
|
||||||
this.allocInode())
|
this.allocInode())
|
||||||
|
|
||||||
return this.buildDir("/", this.root)
|
return this.buildVerDir("/", this.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *version) metadataPath() string {
|
func (this *version) metadataPath() string {
|
||||||
@ -174,11 +179,11 @@ func (this *version) Root() (fs.Node, error) {
|
|||||||
func (this *version) dump(root *versionedDir, depth int) {
|
func (this *version) dump(root *versionedDir, depth int) {
|
||||||
indent := strings.Repeat("\t", depth)
|
indent := strings.Repeat("\t", depth)
|
||||||
for name, dir := range root.dirs {
|
for name, dir := range root.dirs {
|
||||||
fmt.Printf("%s+ %s (%s)\n", indent, name, dir.node.path)
|
fmt.Printf("%s+ %s [%s@%d]\n", indent, name, dir.node.path, dir.node.ver.timestamp.Unix())
|
||||||
this.dump(dir, depth+1)
|
this.dump(dir, depth+1)
|
||||||
}
|
}
|
||||||
for name, file := range root.files {
|
for name, file := range root.files {
|
||||||
fmt.Printf("%s- %s (%s)\n", indent, name, file.node.path)
|
fmt.Printf("%s- %s [%s@%d]\n", indent, name, file.node.path, file.node.ver.timestamp.Unix())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user