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

- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [x] 🐹 Trivial/Minor

## Issue(s)

* #1740

## Test Plan

- [x] 💪 Manual
- [ ]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2022-12-14 16:34:22 -08:00 committed by GitHub
parent 01b8111404
commit c1a0b74d22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/kopia/kopia/fs"
"github.com/kopia/kopia/repo" "github.com/kopia/kopia/repo"
"github.com/kopia/kopia/repo/blob" "github.com/kopia/kopia/repo/blob"
"github.com/kopia/kopia/repo/compression" "github.com/kopia/kopia/repo/compression"
@ -13,6 +14,7 @@ import (
"github.com/kopia/kopia/repo/manifest" "github.com/kopia/kopia/repo/manifest"
"github.com/kopia/kopia/snapshot" "github.com/kopia/kopia/snapshot"
"github.com/kopia/kopia/snapshot/policy" "github.com/kopia/kopia/snapshot/policy"
"github.com/kopia/kopia/snapshot/snapshotfs"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/alcionai/corso/src/internal/common" "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 { type ErrorRepoAlreadyExists struct {
common.Err common.Err
} }
@ -60,7 +66,10 @@ func IsRepoAlreadyExistsError(e error) bool {
return errors.As(e, &erae) return errors.As(e, &erae)
} }
var _ snapshotManager = &conn{} var (
_ snapshotManager = &conn{}
_ snapshotLoader = &conn{}
)
type conn struct { type conn struct {
storage storage.Storage storage storage.Storage
@ -389,3 +398,7 @@ func (w *conn) LoadSnapshots(
) ([]*snapshot.Manifest, error) { ) ([]*snapshot.Manifest, error) {
return snapshot.LoadSnapshots(ctx, w.Repository, ids) return snapshot.LoadSnapshots(ctx, w.Repository, ids)
} }
func (w *conn) SnapshotRoot(man *snapshot.Manifest) (fs.Entry, error) {
return snapshotfs.SnapshotRoot(w.Repository, man)
}