repository: add Checker() method to repository to replace unchecked cast

This commit is contained in:
Michael Eischer
2025-09-28 14:52:41 +02:00
parent 189b295c30
commit f0955fa931
8 changed files with 20 additions and 13 deletions

View File

@@ -51,11 +51,11 @@ func (e *PackError) Error() string {
// Checker handles index-related operations for repository checking.
type Checker struct {
packs map[restic.ID]int64
repo restic.Repository
repo *Repository
}
// NewChecker creates a new Checker.
func NewChecker(repo restic.Repository) *Checker {
func NewChecker(repo *Repository) *Checker {
return &Checker{
packs: make(map[restic.ID]int64),
repo: repo,
@@ -256,7 +256,7 @@ func (c *Checker) ReadPacks(ctx context.Context, packs map[restic.ID]int64, p *p
}
}
err := CheckPack(ctx, c.repo.(*Repository), ps.id, ps.blobs, ps.size, bufRd, dec)
err := CheckPack(ctx, c.repo, ps.id, ps.blobs, ps.size, bufRd, dec)
p.Add(1)
if err == nil {
continue

View File

@@ -347,7 +347,7 @@ var (
depth = 3
)
func createFilledRepo(t testing.TB, snapshots int, version uint) (restic.Repository, restic.Unpacked[restic.FileType]) {
func createFilledRepo(t testing.TB, snapshots int, version uint) (*repository.Repository, restic.Unpacked[restic.FileType]) {
repo, unpacked, _ := repository.TestRepositoryWithVersion(t, version)
for i := 0; i < snapshots; i++ {

View File

@@ -178,6 +178,10 @@ func (r *Repository) SetDryRun() {
r.be = dryrun.New(r.be)
}
func (r *Repository) Checker() *Checker {
return NewChecker(r)
}
// LoadUnpacked loads and decrypts the file with the given type and ID.
func (r *Repository) LoadUnpacked(ctx context.Context, t restic.FileType, id restic.ID) ([]byte, error) {
debug.Log("load %v with id %v", t, id)

View File

@@ -164,7 +164,7 @@ func TestNewLock(_ *testing.T, repo *Repository, exclusive bool) (*restic.Lock,
}
// TestCheckRepo runs the checker on repo.
func TestCheckRepo(t testing.TB, repo restic.Repository) {
func TestCheckRepo(t testing.TB, repo *Repository) {
chkr := NewChecker(repo)
hints, errs := chkr.LoadIndex(context.TODO(), nil)