2015-03-02 13:48:47 +00:00
|
|
|
package restic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
|
2015-04-26 15:44:38 +00:00
|
|
|
"github.com/restic/restic/backend"
|
2015-03-02 13:48:47 +00:00
|
|
|
"github.com/restic/restic/debug"
|
2015-04-26 12:46:15 +00:00
|
|
|
"github.com/restic/restic/server"
|
2015-03-02 13:48:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type WalkTreeJob struct {
|
|
|
|
Path string
|
|
|
|
Error error
|
|
|
|
|
|
|
|
Node *Node
|
|
|
|
Tree *Tree
|
|
|
|
}
|
|
|
|
|
2015-04-26 15:44:38 +00:00
|
|
|
func walkTree(s *server.Server, path string, treeID backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
|
|
|
|
debug.Log("walkTree", "start on %q (%v)", path, treeID.Str())
|
2015-03-02 13:48:47 +00:00
|
|
|
// load tree
|
2015-04-26 15:44:38 +00:00
|
|
|
t, err := LoadTree(s, treeID)
|
2015-03-02 13:48:47 +00: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" {
|
2015-04-26 15:44:38 +00:00
|
|
|
walkTree(s, p, node.Subtree, done, jobCh)
|
2015-03-02 13:48:47 +00:00
|
|
|
} else {
|
2015-03-07 10:53:32 +00:00
|
|
|
jobCh <- WalkTreeJob{Path: p, Node: node, Error: err}
|
2015-03-02 13:48:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-08 19:57:21 +00:00
|
|
|
jobCh <- WalkTreeJob{Path: filepath.Join(path), Tree: t}
|
2015-04-26 15:44:38 +00:00
|
|
|
debug.Log("walkTree", "done for %q (%v)", path, treeID.Str())
|
2015-03-02 13:48:47 +00: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 15:44:38 +00:00
|
|
|
func WalkTree(server *server.Server, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
|
|
|
|
debug.Log("WalkTree", "start on %v", id.Str())
|
|
|
|
walkTree(server, "", id, done, jobCh)
|
2015-03-02 13:48:47 +00:00
|
|
|
close(jobCh)
|
2015-03-08 20:21:31 +00:00
|
|
|
debug.Log("WalkTree", "done")
|
2015-03-02 13:48:47 +00:00
|
|
|
}
|