Support for deleting files

This commit is contained in:
Alex Yatskov 2015-05-15 13:15:19 +09:00
parent 4e23f8f703
commit 8f8288e11c

View File

@ -36,7 +36,16 @@ import (
) )
type versionMetadata struct { type versionMetadata struct {
Deleted []string Deleted []string `json:"deleted"`
}
func (this *versionMetadata) filter(base string, nodes map[string]versionedNode) {
for _, delPath := range this.Deleted {
dir, file := filepath.Split(delPath)
if dir == base {
delete(nodes, file)
}
}
} }
type versionedNode struct { type versionedNode struct {
@ -85,10 +94,13 @@ func (this *version) scanDir(path string) (map[string]versionedNode, error) {
var baseNodes map[string]versionedNode var baseNodes map[string]versionedNode
if this.parent != nil { if this.parent != nil {
var err error var err error
baseNodes, err = this.parent.scanDir(path) baseNodes, err = this.parent.scanDir(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
this.meta.filter(path, baseNodes)
} }
ownNodes := make(map[string]versionedNode) ownNodes := make(map[string]versionedNode)
@ -104,6 +116,8 @@ func (this *version) scanDir(path string) (map[string]versionedNode, error) {
ownNodes[name] = versionedNode{this.rebasePath(path, name), node} ownNodes[name] = versionedNode{this.rebasePath(path, name), node}
} }
} }
this.meta.filter(path, ownNodes)
} }
if baseNodes == nil { if baseNodes == nil {