2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-10 23:31:09 +00:00
restic/walk.go

59 lines
1.5 KiB
Go
Raw Normal View History

2015-03-02 13:48:47 +00:00
package restic
import (
"path/filepath"
"github.com/restic/restic/backend"
"github.com/restic/restic/debug"
)
type WalkTreeJob struct {
Path string
Error error
Node *Node
Tree *Tree
}
func walkTree(s Server, path string, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
debug.Log("walkTree", "start on %q (%v)", path, id.Str())
// load tree
t, err := LoadTree(s, id)
if err != nil {
jobCh <- WalkTreeJob{Path: path, Error: err}
return
}
for _, node := range t.Nodes {
p := filepath.Join(path, node.Name)
if node.Type == "dir" {
blob, err := t.Map.FindID(node.Subtree)
if err != nil {
jobCh <- WalkTreeJob{Path: p, Error: err}
continue
}
walkTree(s, p, blob.Storage, done, jobCh)
} else {
2015-03-07 10:53:32 +00:00
// load old blobs
node.blobs, err = t.Map.Select(node.Content)
if err != nil {
debug.Log("walkTree", "unable to load bobs for %q (%v): %v", path, id.Str(), err)
}
jobCh <- WalkTreeJob{Path: p, Node: node, Error: err}
2015-03-02 13:48:47 +00:00
}
}
jobCh <- WalkTreeJob{Path: filepath.Join(path), Tree: t}
2015-03-02 13:48:47 +00:00
debug.Log("walkTree", "done for %q (%v)", path, id.Str())
}
// WalkTree walks the tree specified by ID recursively and sends a job for each
// file and directory it finds. When the channel done is closed, processing
// stops.
func WalkTree(server Server, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
debug.Log("WalkTree", "start on %v", id.Str())
walkTree(server, "", id, done, jobCh)
close(jobCh)
2015-03-08 20:21:31 +00:00
debug.Log("WalkTree", "done")
2015-03-02 13:48:47 +00:00
}