diff --git a/src/cmds/restic/cmd_prune.go b/src/cmds/restic/cmd_prune.go index e74c73ce9..4705644c7 100644 --- a/src/cmds/restic/cmd_prune.go +++ b/src/cmds/restic/cmd_prune.go @@ -97,7 +97,7 @@ func pruneRepository(gopts GlobalOptions, repo restic.Repository) error { Verbosef("building new index for repo\n") bar := newProgressMax(!gopts.Quiet, uint64(stats.packs), "packs") - idx, err := index.New(ctx, repo, bar) + idx, err := index.New(ctx, repo, restic.NewIDSet(), bar) if err != nil { return err } @@ -222,6 +222,10 @@ func pruneRepository(gopts GlobalOptions, repo restic.Repository) error { bar.Done() } + if err = rebuildIndex(ctx, repo, removePacks); err != nil { + return err + } + if len(removePacks) != 0 { bar = newProgressMax(!gopts.Quiet, uint64(len(removePacks)), "packs deleted") bar.Start() @@ -236,10 +240,6 @@ func pruneRepository(gopts GlobalOptions, repo restic.Repository) error { bar.Done() } - if err = rebuildIndex(ctx, repo); err != nil { - return err - } - Verbosef("done\n") return nil } diff --git a/src/cmds/restic/cmd_rebuild_index.go b/src/cmds/restic/cmd_rebuild_index.go index 6a60ea900..9f3cc888c 100644 --- a/src/cmds/restic/cmd_rebuild_index.go +++ b/src/cmds/restic/cmd_rebuild_index.go @@ -38,10 +38,10 @@ func runRebuildIndex(gopts GlobalOptions) error { ctx, cancel := context.WithCancel(gopts.ctx) defer cancel() - return rebuildIndex(ctx, repo) + return rebuildIndex(ctx, repo, restic.NewIDSet()) } -func rebuildIndex(ctx context.Context, repo restic.Repository) error { +func rebuildIndex(ctx context.Context, repo restic.Repository, ignorePacks restic.IDSet) error { Verbosef("counting files in repo\n") var packs uint64 @@ -50,7 +50,7 @@ func rebuildIndex(ctx context.Context, repo restic.Repository) error { } bar := newProgressMax(!globalOptions.Quiet, packs, "packs") - idx, err := index.New(ctx, repo, bar) + idx, err := index.New(ctx, repo, ignorePacks, bar) if err != nil { return err } diff --git a/src/restic/index/index.go b/src/restic/index/index.go index ab1ebafa4..be528efc0 100644 --- a/src/restic/index/index.go +++ b/src/restic/index/index.go @@ -34,12 +34,12 @@ func newIndex() *Index { } // New creates a new index for repo from scratch. -func New(ctx context.Context, repo restic.Repository, p *restic.Progress) (*Index, error) { +func New(ctx context.Context, repo restic.Repository, ignorePacks restic.IDSet, p *restic.Progress) (*Index, error) { p.Start() defer p.Done() ch := make(chan worker.Job) - go list.AllPacks(ctx, repo, ch) + go list.AllPacks(ctx, repo, ignorePacks, ch) idx := newIndex() diff --git a/src/restic/list/list.go b/src/restic/list/list.go index 292ba8475..6bd9d23aa 100644 --- a/src/restic/list/list.go +++ b/src/restic/list/list.go @@ -37,7 +37,7 @@ func (l Result) Entries() []restic.Blob { } // AllPacks sends the contents of all packs to ch. -func AllPacks(ctx context.Context, repo Lister, ch chan<- worker.Job) { +func AllPacks(ctx context.Context, repo Lister, ignorePacks restic.IDSet, ch chan<- worker.Job) { f := func(ctx context.Context, job worker.Job) (interface{}, error) { packID := job.Data.(restic.ID) entries, size, err := repo.ListPack(ctx, packID) @@ -55,6 +55,10 @@ func AllPacks(ctx context.Context, repo Lister, ch chan<- worker.Job) { go func() { defer close(jobCh) for id := range repo.List(ctx, restic.DataFile) { + if ignorePacks.Has(id) { + continue + } + select { case jobCh <- worker.Job{Data: id}: case <-ctx.Done():