forked from TrueCloudLab/restic
repository: remove SaveIndex from interface
The method is now only indirectly accessible via Prune or RepairIndex.
This commit is contained in:
parent
fb59e00614
commit
550d1eeac3
7 changed files with 22 additions and 52 deletions
|
@ -312,10 +312,17 @@ func (mi *MasterIndex) Load(ctx context.Context, r restic.ListerLoaderUnpacked,
|
|||
return mi.MergeFinalIndexes()
|
||||
}
|
||||
|
||||
type MasterIndexSaveOpts struct {
|
||||
SaveProgress *progress.Counter
|
||||
DeleteProgress func() *progress.Counter
|
||||
DeleteReport func(id restic.ID, err error)
|
||||
SkipDeletion bool
|
||||
}
|
||||
|
||||
// Save saves all known indexes to index files, leaving out any
|
||||
// packs whose ID is contained in packBlacklist from finalized indexes.
|
||||
// It also removes the old index files and those listed in extraObsolete.
|
||||
func (mi *MasterIndex) Save(ctx context.Context, repo restic.SaverRemoverUnpacked, excludePacks restic.IDSet, extraObsolete restic.IDs, opts restic.MasterIndexSaveOpts) error {
|
||||
func (mi *MasterIndex) Save(ctx context.Context, repo restic.SaverRemoverUnpacked, excludePacks restic.IDSet, extraObsolete restic.IDs, opts MasterIndexSaveOpts) error {
|
||||
p := opts.SaveProgress
|
||||
p.SetMax(uint64(len(mi.Packs(excludePacks))))
|
||||
|
||||
|
|
|
@ -364,7 +364,7 @@ func testIndexSave(t *testing.T, version uint) {
|
|||
blobs[pb] = struct{}{}
|
||||
}))
|
||||
|
||||
rtest.OK(t, idx.Save(context.TODO(), repo, nil, nil, restic.MasterIndexSaveOpts{}))
|
||||
rtest.OK(t, idx.Save(context.TODO(), repo, nil, nil, index.MasterIndexSaveOpts{}))
|
||||
idx = index.NewMasterIndex()
|
||||
rtest.OK(t, idx.Load(context.TODO(), repo, nil, nil))
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/backend"
|
||||
"github.com/restic/restic/internal/index"
|
||||
"github.com/restic/restic/internal/repository"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
"github.com/restic/restic/internal/ui/progress"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
|
@ -173,35 +173,12 @@ func repack(t *testing.T, repo restic.Repository, packs restic.IDSet, blobs rest
|
|||
}
|
||||
}
|
||||
|
||||
func rebuildIndex(t *testing.T, repo restic.Repository) {
|
||||
err := repo.SetIndex(index.NewMasterIndex())
|
||||
rtest.OK(t, err)
|
||||
func rebuildAndReloadIndex(t *testing.T, repo *repository.Repository) {
|
||||
rtest.OK(t, repository.RepairIndex(context.TODO(), repo, repository.RepairIndexOptions{
|
||||
ReadAllPacks: true,
|
||||
}, &progress.NoopPrinter{}))
|
||||
|
||||
packs := make(map[restic.ID]int64)
|
||||
err = repo.List(context.TODO(), restic.PackFile, func(id restic.ID, size int64) error {
|
||||
packs[id] = size
|
||||
return nil
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
|
||||
_, err = repo.(*repository.Repository).CreateIndexFromPacks(context.TODO(), packs, nil)
|
||||
rtest.OK(t, err)
|
||||
|
||||
var obsoleteIndexes restic.IDs
|
||||
err = repo.List(context.TODO(), restic.IndexFile, func(id restic.ID, size int64) error {
|
||||
obsoleteIndexes = append(obsoleteIndexes, id)
|
||||
return nil
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
|
||||
err = repo.SaveIndex(context.TODO(), restic.NewIDSet(), obsoleteIndexes, restic.MasterIndexSaveOpts{})
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
||||
func reloadIndex(t *testing.T, repo restic.Repository) {
|
||||
if err := repo.LoadIndex(context.TODO(), nil); err != nil {
|
||||
t.Fatalf("error loading new index: %v", err)
|
||||
}
|
||||
rtest.OK(t, repo.LoadIndex(context.TODO(), nil))
|
||||
}
|
||||
|
||||
func TestRepack(t *testing.T) {
|
||||
|
@ -236,8 +213,7 @@ func testRepack(t *testing.T, version uint) {
|
|||
removePacks := findPacksForBlobs(t, repo, removeBlobs)
|
||||
|
||||
repack(t, repo, removePacks, keepBlobs)
|
||||
rebuildIndex(t, repo)
|
||||
reloadIndex(t, repo)
|
||||
rebuildAndReloadIndex(t, repo)
|
||||
|
||||
packsAfter = listPacks(t, repo)
|
||||
for id := range removePacks {
|
||||
|
@ -307,8 +283,7 @@ func testRepackCopy(t *testing.T, version uint) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rebuildIndex(t, dstRepo)
|
||||
reloadIndex(t, dstRepo)
|
||||
rebuildAndReloadIndex(t, dstRepo)
|
||||
|
||||
for h := range keepBlobs {
|
||||
list := dstRepo.LookupBlob(h.Type, h.ID)
|
||||
|
|
|
@ -28,6 +28,8 @@ func RepairIndex(ctx context.Context, repo *Repository, opts RepairIndexOptions,
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
repo.clearIndex()
|
||||
|
||||
} else {
|
||||
printer.P("loading indexes...\n")
|
||||
mi := index.NewMasterIndex()
|
||||
|
@ -111,11 +113,11 @@ func RepairIndex(ctx context.Context, repo *Repository, opts RepairIndexOptions,
|
|||
return nil
|
||||
}
|
||||
|
||||
func rebuildIndexFiles(ctx context.Context, repo restic.Repository, removePacks restic.IDSet, extraObsolete restic.IDs, skipDeletion bool, printer progress.Printer) error {
|
||||
func rebuildIndexFiles(ctx context.Context, repo *Repository, removePacks restic.IDSet, extraObsolete restic.IDs, skipDeletion bool, printer progress.Printer) error {
|
||||
printer.P("rebuilding index\n")
|
||||
|
||||
bar := printer.NewCounter("packs processed")
|
||||
return repo.SaveIndex(ctx, removePacks, extraObsolete, restic.MasterIndexSaveOpts{
|
||||
return repo.idx.Save(ctx, repo, removePacks, extraObsolete, index.MasterIndexSaveOpts{
|
||||
SaveProgress: bar,
|
||||
DeleteProgress: func() *progress.Counter {
|
||||
return printer.NewCounter("old indexes deleted")
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func RepairPacks(ctx context.Context, repo restic.Repository, ids restic.IDSet, printer progress.Printer) error {
|
||||
func RepairPacks(ctx context.Context, repo *Repository, ids restic.IDSet, printer progress.Printer) error {
|
||||
wg, wgCtx := errgroup.WithContext(ctx)
|
||||
repo.StartPackUploader(wgCtx, wg)
|
||||
|
||||
|
|
|
@ -587,10 +587,6 @@ func (r *Repository) LookupBlobSize(tpe restic.BlobType, id restic.ID) (uint, bo
|
|||
return r.idx.LookupSize(restic.BlobHandle{Type: tpe, ID: id})
|
||||
}
|
||||
|
||||
func (r *Repository) SaveIndex(ctx context.Context, excludePacks restic.IDSet, extraObsolete restic.IDs, opts restic.MasterIndexSaveOpts) error {
|
||||
return r.idx.Save(ctx, r, excludePacks, extraObsolete, opts)
|
||||
}
|
||||
|
||||
// ListBlobs runs fn on all blobs known to the index. When the context is cancelled,
|
||||
// the index iteration returns immediately with ctx.Err(). This blocks any modification of the index.
|
||||
func (r *Repository) ListBlobs(ctx context.Context, fn func(restic.PackedBlob)) error {
|
||||
|
|
|
@ -23,7 +23,6 @@ type Repository interface {
|
|||
|
||||
LoadIndex(ctx context.Context, p *progress.Counter) error
|
||||
SetIndex(mi MasterIndex) error
|
||||
SaveIndex(ctx context.Context, excludePacks IDSet, extraObsolete IDs, opts MasterIndexSaveOpts) error
|
||||
|
||||
LookupBlob(t BlobType, id ID) []PackedBlob
|
||||
LookupBlobSize(t BlobType, id ID) (size uint, exists bool)
|
||||
|
@ -106,13 +105,6 @@ type PackBlobs struct {
|
|||
Blobs []Blob
|
||||
}
|
||||
|
||||
type MasterIndexSaveOpts struct {
|
||||
SaveProgress *progress.Counter
|
||||
DeleteProgress func() *progress.Counter
|
||||
DeleteReport func(id ID, err error)
|
||||
SkipDeletion bool
|
||||
}
|
||||
|
||||
// MasterIndex keeps track of the blobs are stored within files.
|
||||
type MasterIndex interface {
|
||||
Has(bh BlobHandle) bool
|
||||
|
@ -122,8 +114,6 @@ type MasterIndex interface {
|
|||
// the index iteration returns immediately with ctx.Err(). This blocks any modification of the index.
|
||||
Each(ctx context.Context, fn func(PackedBlob)) error
|
||||
ListPacks(ctx context.Context, packs IDSet) <-chan PackBlobs
|
||||
|
||||
Save(ctx context.Context, repo SaverRemoverUnpacked, excludePacks IDSet, extraObsolete IDs, opts MasterIndexSaveOpts) error
|
||||
}
|
||||
|
||||
// Lister allows listing files in a backend.
|
||||
|
|
Loading…
Reference in a new issue