From c1a0b74d220226de45a0ad1de21002b4d878f97a Mon Sep 17 00:00:00 2001 From: ashmrtn Date: Wed, 14 Dec 2022 16:34:22 -0800 Subject: [PATCH] Helper function to load snapshot root directories (#1796) ## Description Add a helper function that allows loading the root directory of a snapshot given the snapshot manifest. This will allow future code for merging directory hierarchies to be tested without having to involve an actual instance of kopia with some previously created snapshots. ## Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [ ] :computer: CI/Deployment - [x] :hamster: Trivial/Minor ## Issue(s) * #1740 ## Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/kopia/conn.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/internal/kopia/conn.go b/src/internal/kopia/conn.go index 40929987d..1756de6ea 100644 --- a/src/internal/kopia/conn.go +++ b/src/internal/kopia/conn.go @@ -6,6 +6,7 @@ import ( "sync" "time" + "github.com/kopia/kopia/fs" "github.com/kopia/kopia/repo" "github.com/kopia/kopia/repo/blob" "github.com/kopia/kopia/repo/compression" @@ -13,6 +14,7 @@ import ( "github.com/kopia/kopia/repo/manifest" "github.com/kopia/kopia/snapshot" "github.com/kopia/kopia/snapshot/policy" + "github.com/kopia/kopia/snapshot/snapshotfs" "github.com/pkg/errors" "github.com/alcionai/corso/src/internal/common" @@ -47,6 +49,10 @@ var ( } ) +type snapshotLoader interface { + SnapshotRoot(man *snapshot.Manifest) (fs.Entry, error) +} + type ErrorRepoAlreadyExists struct { common.Err } @@ -60,7 +66,10 @@ func IsRepoAlreadyExistsError(e error) bool { return errors.As(e, &erae) } -var _ snapshotManager = &conn{} +var ( + _ snapshotManager = &conn{} + _ snapshotLoader = &conn{} +) type conn struct { storage storage.Storage @@ -389,3 +398,7 @@ func (w *conn) LoadSnapshots( ) ([]*snapshot.Manifest, error) { return snapshot.LoadSnapshots(ctx, w.Repository, ids) } + +func (w *conn) SnapshotRoot(man *snapshot.Manifest) (fs.Entry, error) { + return snapshotfs.SnapshotRoot(w.Repository, man) +}