1
0
mirror of https://github.com/restic/restic.git synced 2024-06-29 08:10:52 +02:00
restic/walk.go

59 lines
1.5 KiB
Go
Raw Normal View History

2015-03-02 14:48:47 +01:00
package restic
import (
"path/filepath"
"github.com/restic/restic/debug"
2015-04-26 14:46:15 +02:00
"github.com/restic/restic/server"
2015-03-02 14:48:47 +01:00
)
type WalkTreeJob struct {
Path string
Error error
Node *Node
Tree *Tree
}
2015-04-26 14:46:15 +02:00
func walkTree(s *server.Server, path string, treeBlob server.Blob, done chan struct{}, jobCh chan<- WalkTreeJob) {
debug.Log("walkTree", "start on %q (%v)", path, treeBlob)
2015-03-02 14:48:47 +01:00
// load tree
t, err := LoadTree(s, treeBlob)
2015-03-02 14:48:47 +01:00
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, done, jobCh)
2015-03-02 14:48:47 +01:00
} else {
2015-03-07 11:53:32 +01: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, treeBlob, err)
2015-03-07 11:53:32 +01:00
}
jobCh <- WalkTreeJob{Path: p, Node: node, Error: err}
2015-03-02 14:48:47 +01:00
}
}
jobCh <- WalkTreeJob{Path: filepath.Join(path), Tree: t}
debug.Log("walkTree", "done for %q (%v)", path, treeBlob)
2015-03-02 14:48:47 +01:00
}
// 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.
2015-04-26 14:46:15 +02:00
func WalkTree(server *server.Server, blob server.Blob, done chan struct{}, jobCh chan<- WalkTreeJob) {
debug.Log("WalkTree", "start on %v", blob)
walkTree(server, "", blob, done, jobCh)
2015-03-02 14:48:47 +01:00
close(jobCh)
2015-03-08 21:21:31 +01:00
debug.Log("WalkTree", "done")
2015-03-02 14:48:47 +01:00
}