repository: extract Load/StoreJSONUnpacked

A Load/Store method for each data type is much clearer. As a result the
repository no longer needs a method to load / store json.
This commit is contained in:
Michael Eischer
2022-07-17 13:22:00 +02:00
parent fbcbd5318c
commit 89d3ce852b
22 changed files with 130 additions and 127 deletions
+3 -4
View File
@@ -79,7 +79,7 @@ func runCat(gopts GlobalOptions, args []string) error {
Println(string(buf))
return nil
case "index":
buf, err := repo.LoadUnpacked(gopts.ctx, nil, restic.IndexFile, id)
buf, err := repo.LoadUnpacked(gopts.ctx, restic.IndexFile, id, nil)
if err != nil {
return err
}
@@ -87,13 +87,12 @@ func runCat(gopts GlobalOptions, args []string) error {
Println(string(buf))
return nil
case "snapshot":
sn := &restic.Snapshot{}
err = repo.LoadJSONUnpacked(gopts.ctx, restic.SnapshotFile, id, sn)
sn, err := restic.LoadSnapshot(gopts.ctx, repo, id)
if err != nil {
return err
}
buf, err := json.MarshalIndent(&sn, "", " ")
buf, err := json.MarshalIndent(sn, "", " ")
if err != nil {
return err
}
+1 -1
View File
@@ -154,7 +154,7 @@ func runCopy(opts CopyOptions, gopts GlobalOptions, args []string) error {
if sn.Original == nil {
sn.Original = sn.ID()
}
newID, err := dstRepo.SaveJSONUnpacked(ctx, restic.SnapshotFile, sn)
newID, err := restic.SaveSnapshot(ctx, dstRepo, sn)
if err != nil {
return err
}
+1 -1
View File
@@ -166,7 +166,7 @@ func createSnapshot(ctx context.Context, name, hostname string, tags []string, r
sn.Tree = tree
id, err := repo.SaveJSONUnpacked(ctx, restic.SnapshotFile, sn)
id, err := restic.SaveSnapshot(ctx, repo, sn)
if err != nil {
return errors.Fatalf("unable to save snapshot: %v", err)
}
+1 -1
View File
@@ -82,7 +82,7 @@ func changeTags(ctx context.Context, repo *repository.Repository, sn *restic.Sna
}
// Save the new snapshot.
id, err := repo.SaveJSONUnpacked(ctx, restic.SnapshotFile, sn)
id, err := restic.SaveSnapshot(ctx, repo, sn)
if err != nil {
return false, err
}
+1 -1
View File
@@ -8,7 +8,7 @@ import (
)
// FindFilteredSnapshots yields Snapshots, either given explicitly by `snapshotIDs` or filtered from the list of all snapshots.
func FindFilteredSnapshots(ctx context.Context, be restic.Lister, loader restic.LoadJSONUnpackeder, hosts []string, tags []restic.TagList, paths []string, snapshotIDs []string) <-chan *restic.Snapshot {
func FindFilteredSnapshots(ctx context.Context, be restic.Lister, loader restic.LoaderUnpacked, hosts []string, tags []restic.TagList, paths []string, snapshotIDs []string) <-chan *restic.Snapshot {
out := make(chan *restic.Snapshot)
go func() {
defer close(out)