2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 23:06:32 +00:00

Add extraObsolete to MasterIndex.Save

This commit is contained in:
Alexander Weiss 2020-10-18 09:24:34 +02:00
parent 5898cb341f
commit 1ec628ddf5
4 changed files with 18 additions and 17 deletions

View File

@ -498,7 +498,7 @@ func prune(opts PruneOptions, gopts GlobalOptions, repo restic.Repository, usedB
if len(removePacks) != 0 { if len(removePacks) != 0 {
totalpacks := int(stats.packs.used+stats.packs.partlyUsed+stats.packs.unused) - totalpacks := int(stats.packs.used+stats.packs.partlyUsed+stats.packs.unused) -
len(removePacks) + packsAddedByRepack len(removePacks) + packsAddedByRepack
err = rebuildIndexFiles(gopts, repo, removePacks, uint64(totalpacks)) err = rebuildIndexFiles(gopts, repo, removePacks, nil, uint64(totalpacks))
if err != nil { if err != nil {
return err return err
} }
@ -511,12 +511,12 @@ func prune(opts PruneOptions, gopts GlobalOptions, repo restic.Repository, usedB
return nil return nil
} }
func rebuildIndexFiles(gopts GlobalOptions, repo restic.Repository, removePacks restic.IDSet, packcount uint64) error { func rebuildIndexFiles(gopts GlobalOptions, repo restic.Repository, removePacks restic.IDSet, extraObsolete restic.IDs, packcount uint64) error {
Verbosef("rebuilding index\n") Verbosef("rebuilding index\n")
bar := newProgressMax(!gopts.Quiet, packcount, "packs processed") bar := newProgressMax(!gopts.Quiet, packcount, "packs processed")
obsoleteIndexes, err := (repo.Index()).(*repository.MasterIndex). obsoleteIndexes, err := (repo.Index()).(*repository.MasterIndex).
Save(gopts.ctx, repo, removePacks, bar) Save(gopts.ctx, repo, removePacks, extraObsolete, bar)
bar.Done() bar.Done()
if err != nil { if err != nil {
return err return err

View File

@ -266,7 +266,7 @@ func (mi *MasterIndex) MergeFinalIndexes() {
// of all known indexes in the "supersedes" field. The IDs are also returned in // of all known indexes in the "supersedes" field. The IDs are also returned in
// the IDSet obsolete // the IDSet obsolete
// After calling this function, you should remove the obsolete index files. // After calling this function, you should remove the obsolete index files.
func (mi *MasterIndex) Save(ctx context.Context, repo restic.Repository, packBlacklist restic.IDSet, p *progress.Counter) (obsolete restic.IDSet, err error) { func (mi *MasterIndex) Save(ctx context.Context, repo restic.Repository, packBlacklist restic.IDSet, extraObsolete restic.IDs, p *progress.Counter) (obsolete restic.IDSet, err error) {
mi.idxMutex.Lock() mi.idxMutex.Lock()
defer mi.idxMutex.Unlock() defer mi.idxMutex.Unlock()
@ -275,15 +275,6 @@ func (mi *MasterIndex) Save(ctx context.Context, repo restic.Repository, packBla
newIndex := NewIndex() newIndex := NewIndex()
obsolete = restic.NewIDSet() obsolete = restic.NewIDSet()
finalize := func() error {
newIndex.Finalize()
if _, err := SaveIndex(ctx, repo, newIndex); err != nil {
return err
}
newIndex = NewIndex()
return nil
}
for i, idx := range mi.idx { for i, idx := range mi.idx {
if idx.Final() { if idx.Final() {
ids, err := idx.IDs() ids, err := idx.IDs()
@ -309,13 +300,23 @@ func (mi *MasterIndex) Save(ctx context.Context, repo restic.Repository, packBla
newIndex.StorePack(pbs.packID, pbs.blobs) newIndex.StorePack(pbs.packID, pbs.blobs)
p.Add(1) p.Add(1)
if IndexFull(newIndex) { if IndexFull(newIndex) {
if err := finalize(); err != nil { newIndex.Finalize()
if _, err := SaveIndex(ctx, repo, newIndex); err != nil {
return nil, err return nil, err
} }
newIndex = NewIndex()
} }
} }
} }
if err := finalize(); err != nil {
err = newIndex.AddToSupersedes(extraObsolete...)
if err != nil {
return nil, err
}
obsolete.Merge(restic.NewIDSet(extraObsolete...))
newIndex.Finalize()
if _, err := SaveIndex(ctx, repo, newIndex); err != nil {
return nil, err return nil, err
} }

View File

@ -346,7 +346,7 @@ func TestIndexSave(t *testing.T) {
repo.LoadIndex(context.TODO()) repo.LoadIndex(context.TODO())
obsoletes, err := repo.Index().(*repository.MasterIndex).Save(context.TODO(), repo, nil, nil) obsoletes, err := repo.Index().(*repository.MasterIndex).Save(context.TODO(), repo, nil, nil, nil)
if err != nil { if err != nil {
t.Fatalf("unable to save new index: %v", err) t.Fatalf("unable to save new index: %v", err)
} }

View File

@ -193,7 +193,7 @@ func rebuildIndex(t *testing.T, repo restic.Repository) {
} }
_, err = (repo.Index()).(*repository.MasterIndex). _, err = (repo.Index()).(*repository.MasterIndex).
Save(context.TODO(), repo, restic.NewIDSet(), nil) Save(context.TODO(), repo, restic.NewIDSet(), nil, nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)