mirror of
https://github.com/restic/restic.git
synced 2025-12-03 21:21:47 +00:00
Replace restic.Progress with new progress.Counter
This fixes two race conditions while cleaning up the code.
This commit is contained in:
@@ -11,6 +11,8 @@ import (
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/pack"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
"github.com/restic/restic/internal/ui/progress"
|
||||
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
@@ -48,8 +50,7 @@ type Lister interface {
|
||||
|
||||
// New creates a new index for repo from scratch. InvalidFiles contains all IDs
|
||||
// of files that cannot be listed successfully.
|
||||
func New(ctx context.Context, repo Lister, ignorePacks restic.IDSet, p *restic.Progress) (idx *Index, invalidFiles restic.IDs, err error) {
|
||||
p.Start()
|
||||
func New(ctx context.Context, repo Lister, ignorePacks restic.IDSet, p *progress.Counter) (idx *Index, invalidFiles restic.IDs, err error) {
|
||||
defer p.Done()
|
||||
|
||||
type Job struct {
|
||||
@@ -118,7 +119,7 @@ func New(ctx context.Context, repo Lister, ignorePacks restic.IDSet, p *restic.P
|
||||
idx = newIndex()
|
||||
|
||||
for res := range outputCh {
|
||||
p.Report(restic.Stat{Blobs: 1})
|
||||
p.Add(1)
|
||||
if res.Error != nil {
|
||||
cause := errors.Cause(res.Error)
|
||||
if _, ok := cause.(pack.InvalidFileError); ok {
|
||||
@@ -187,10 +188,9 @@ func loadIndexJSON(ctx context.Context, repo ListLoader, id restic.ID) (*indexJS
|
||||
}
|
||||
|
||||
// Load creates an index by loading all index files from the repo.
|
||||
func Load(ctx context.Context, repo ListLoader, p *restic.Progress) (*Index, error) {
|
||||
func Load(ctx context.Context, repo ListLoader, p *progress.Counter) (*Index, error) {
|
||||
debug.Log("loading indexes")
|
||||
|
||||
p.Start()
|
||||
defer p.Done()
|
||||
|
||||
supersedes := make(map[restic.ID]restic.IDSet)
|
||||
@@ -199,7 +199,7 @@ func Load(ctx context.Context, repo ListLoader, p *restic.Progress) (*Index, err
|
||||
index := newIndex()
|
||||
|
||||
err := repo.List(ctx, restic.IndexFile, func(id restic.ID, size int64) error {
|
||||
p.Report(restic.Stat{Blobs: 1})
|
||||
p.Add(1)
|
||||
|
||||
debug.Log("Load index %v", id)
|
||||
idx, err := loadIndexJSON(ctx, repo, id)
|
||||
|
||||
Reference in New Issue
Block a user