mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +00:00
make repo for tree walker mockable
This commit is contained in:
parent
7711fcda69
commit
50fd8f6f44
7
tree.go
7
tree.go
@ -8,7 +8,6 @@ import (
|
||||
"github.com/restic/restic/backend"
|
||||
"github.com/restic/restic/debug"
|
||||
"github.com/restic/restic/pack"
|
||||
"github.com/restic/restic/repository"
|
||||
)
|
||||
|
||||
type Tree struct {
|
||||
@ -30,7 +29,11 @@ func (t Tree) String() string {
|
||||
return fmt.Sprintf("Tree<%d nodes>", len(t.Nodes))
|
||||
}
|
||||
|
||||
func LoadTree(repo *repository.Repository, id backend.ID) (*Tree, error) {
|
||||
type TreeLoader interface {
|
||||
LoadJSONPack(pack.BlobType, backend.ID, interface{}) error
|
||||
}
|
||||
|
||||
func LoadTree(repo TreeLoader, id backend.ID) (*Tree, error) {
|
||||
tree := &Tree{}
|
||||
err := repo.LoadJSONPack(pack.Tree, id, tree)
|
||||
if err != nil {
|
||||
|
5
walk.go
5
walk.go
@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/restic/restic/backend"
|
||||
"github.com/restic/restic/debug"
|
||||
"github.com/restic/restic/repository"
|
||||
)
|
||||
|
||||
type WalkTreeJob struct {
|
||||
@ -16,7 +15,7 @@ type WalkTreeJob struct {
|
||||
Tree *Tree
|
||||
}
|
||||
|
||||
func walkTree(repo *repository.Repository, path string, treeID backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
|
||||
func walkTree(repo TreeLoader, path string, treeID backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
|
||||
debug.Log("walkTree", "start on %q (%v)", path, treeID.Str())
|
||||
|
||||
t, err := LoadTree(repo, treeID)
|
||||
@ -54,7 +53,7 @@ func walkTree(repo *repository.Repository, path string, treeID backend.ID, done
|
||||
// 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(repo *repository.Repository, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
|
||||
func WalkTree(repo TreeLoader, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
|
||||
debug.Log("WalkTree", "start on %v", id.Str())
|
||||
walkTree(repo, "", id, done, jobCh)
|
||||
close(jobCh)
|
||||
|
Loading…
Reference in New Issue
Block a user