repository: extract LoadTree/SaveTree

The repository has no real idea what a Tree is. So these methods never
belonged there.
This commit is contained in:
Michael Eischer
2022-07-17 13:11:28 +02:00
parent d9ea1e9ee2
commit fbcbd5318c
22 changed files with 150 additions and 133 deletions
+11 -2
View File
@@ -67,13 +67,22 @@ func buildTreeMap(tree TestTree, m TreeMap) restic.ID {
// TreeMap returns the trees from the map on LoadTree.
type TreeMap map[restic.ID]*restic.Tree
func (t TreeMap) LoadTree(ctx context.Context, id restic.ID) (*restic.Tree, error) {
func (t TreeMap) LoadBlob(ctx context.Context, tpe restic.BlobType, id restic.ID, buf []byte) ([]byte, error) {
if tpe != restic.TreeBlob {
return nil, errors.New("can only load trees")
}
tree, ok := t[id]
if !ok {
return nil, errors.New("tree not found")
}
return tree, nil
tbuf, err := json.Marshal(tree)
if err != nil {
panic(err)
}
tbuf = append(tbuf, '\n')
return tbuf, nil
}
func (t TreeMap) Connections() uint {