@@ -285,17 +285,21 @@ func determineResumePosition(ctx context.Context, tracker *Checkpointer, buckets
285285 }
286286}
287287
288+ // scanBuckets scans the given buckets using the given role and adds the number
289+ // of objects it scanned to totalObjectCount. The counter is owned by Chunks and
290+ // shared across role passes so that the completion message reflects the whole
291+ // scan, not just the last role's pass.
288292func (s * Source ) scanBuckets (
289293 ctx context.Context ,
290294 client * s3.Client ,
291295 role string ,
292296 bucketsToScan []string ,
293297 chunksChan chan * sources.Chunk ,
298+ totalObjectCount * uint64 ,
294299) {
295300 if role != "" {
296301 ctx = context .WithValue (ctx , "role" , role )
297302 }
298- var totalObjectCount uint64
299303
300304 checkpointer := NewCheckpointer (ctx , & s .Progress , false )
301305 pos := determineResumePosition (ctx , checkpointer , bucketsToScan )
@@ -340,13 +344,13 @@ func (s *Source) scanBuckets(
340344 }
341345
342346 objectCount := s .scanBucket (ctx , client , role , bucket , sources.ChanReporter {Ch : chunksChan }, startAfter , checkpointer )
343- totalObjectCount += objectCount
347+ * totalObjectCount += objectCount
344348 }
345349
346350 s .SetProgressComplete (
347351 len (bucketsToScan ),
348352 len (bucketsToScan ),
349- fmt .Sprintf ("Completed scanning source %s. %d objects scanned." , s .name , totalObjectCount ),
353+ fmt .Sprintf ("Completed scanning source %s. %d objects scanned." , s .name , * totalObjectCount ),
350354 "" ,
351355 )
352356}
@@ -435,8 +439,9 @@ func (s *Source) listErrorsAreExpected(role string) bool {
435439
436440// Chunks emits chunks of bytes over a channel.
437441func (s * Source ) Chunks (ctx context.Context , chunksChan chan * sources.Chunk , _ ... sources.ChunkingTarget ) error {
442+ var totalObjectCount uint64
438443 visitor := func (c context.Context , defaultRegionClient * s3.Client , roleArn string , buckets []string ) error {
439- s .scanBuckets (c , defaultRegionClient , roleArn , buckets , chunksChan )
444+ s .scanBuckets (c , defaultRegionClient , roleArn , buckets , chunksChan , & totalObjectCount )
440445 return nil
441446 }
442447
0 commit comments