mirror of
https://github.com/octoleo/restic.git
synced 2025-01-11 10:18:10 +00:00
parent
bd7d5a429f
commit
6f24d038f8
@ -97,7 +97,7 @@ func pruneRepository(gopts GlobalOptions, repo restic.Repository) error {
|
|||||||
Verbosef("building new index for repo\n")
|
Verbosef("building new index for repo\n")
|
||||||
|
|
||||||
bar := newProgressMax(!gopts.Quiet, uint64(stats.packs), "packs")
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -222,6 +222,10 @@ func pruneRepository(gopts GlobalOptions, repo restic.Repository) error {
|
|||||||
bar.Done()
|
bar.Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = rebuildIndex(ctx, repo, removePacks); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if len(removePacks) != 0 {
|
if len(removePacks) != 0 {
|
||||||
bar = newProgressMax(!gopts.Quiet, uint64(len(removePacks)), "packs deleted")
|
bar = newProgressMax(!gopts.Quiet, uint64(len(removePacks)), "packs deleted")
|
||||||
bar.Start()
|
bar.Start()
|
||||||
@ -236,10 +240,6 @@ func pruneRepository(gopts GlobalOptions, repo restic.Repository) error {
|
|||||||
bar.Done()
|
bar.Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = rebuildIndex(ctx, repo); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
Verbosef("done\n")
|
Verbosef("done\n")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -38,10 +38,10 @@ func runRebuildIndex(gopts GlobalOptions) error {
|
|||||||
|
|
||||||
ctx, cancel := context.WithCancel(gopts.ctx)
|
ctx, cancel := context.WithCancel(gopts.ctx)
|
||||||
defer cancel()
|
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")
|
Verbosef("counting files in repo\n")
|
||||||
|
|
||||||
var packs uint64
|
var packs uint64
|
||||||
@ -50,7 +50,7 @@ func rebuildIndex(ctx context.Context, repo restic.Repository) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bar := newProgressMax(!globalOptions.Quiet, packs, "packs")
|
bar := newProgressMax(!globalOptions.Quiet, packs, "packs")
|
||||||
idx, err := index.New(ctx, repo, bar)
|
idx, err := index.New(ctx, repo, ignorePacks, bar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -34,12 +34,12 @@ func newIndex() *Index {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new index for repo from scratch.
|
// 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()
|
p.Start()
|
||||||
defer p.Done()
|
defer p.Done()
|
||||||
|
|
||||||
ch := make(chan worker.Job)
|
ch := make(chan worker.Job)
|
||||||
go list.AllPacks(ctx, repo, ch)
|
go list.AllPacks(ctx, repo, ignorePacks, ch)
|
||||||
|
|
||||||
idx := newIndex()
|
idx := newIndex()
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ func (l Result) Entries() []restic.Blob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AllPacks sends the contents of all packs to ch.
|
// 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) {
|
f := func(ctx context.Context, job worker.Job) (interface{}, error) {
|
||||||
packID := job.Data.(restic.ID)
|
packID := job.Data.(restic.ID)
|
||||||
entries, size, err := repo.ListPack(ctx, packID)
|
entries, size, err := repo.ListPack(ctx, packID)
|
||||||
@ -55,6 +55,10 @@ func AllPacks(ctx context.Context, repo Lister, ch chan<- worker.Job) {
|
|||||||
go func() {
|
go func() {
|
||||||
defer close(jobCh)
|
defer close(jobCh)
|
||||||
for id := range repo.List(ctx, restic.DataFile) {
|
for id := range repo.List(ctx, restic.DataFile) {
|
||||||
|
if ignorePacks.Has(id) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case jobCh <- worker.Job{Data: id}:
|
case jobCh <- worker.Job{Data: id}:
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
Loading…
Reference in New Issue
Block a user