MCPcopy
hub / github.com/perkeep/perkeep / EnumerateAllFrom

Function EnumerateAllFrom

pkg/blobserver/enumerate.go:34–67  ·  view source on GitHub ↗

EnumerateAllFrom is like EnumerateAll, but takes an after parameter.

(ctx context.Context, src BlobEnumerator, after string, fn func(blob.SizedRef) error)

Source from the content-addressed store, hash-verified

32
33// EnumerateAllFrom is like EnumerateAll, but takes an after parameter.
34func EnumerateAllFrom(ctx context.Context, src BlobEnumerator, after string, fn func(blob.SizedRef) error) error {
35 const batchSize = 1000
36 var mu sync.Mutex // protects returning with an error while fn is still running
37 errc := make(chan error, 1)
38 for {
39 ch := make(chan blob.SizedRef, 16)
40 n := 0
41 go func() {
42 var err error
43 for sb := range ch {
44 if err != nil {
45 continue
46 }
47 mu.Lock()
48 err = fn(sb)
49 mu.Unlock()
50 after = sb.Ref.String()
51 n++
52 }
53 errc <- err
54 }()
55 err := src.EnumerateBlobs(ctx, ch, after, batchSize)
56 if err != nil {
57 mu.Lock() // make sure fn callback finished; no need to unlock
58 return err
59 }
60 if err := <-errc; err != nil {
61 return err
62 }
63 if n == 0 {
64 return nil
65 }
66 }
67}
68
69// RefTypes returns a list of blobref types appearing on the provided enumerator.
70// A blobref type is a string like "sha1", or whatever is on the left side

Callers 7

StreamBlobsMethod · 0.92
StreamBlobsMethod · 0.92
checkLargeIntegrityMethod · 0.92
reindexMethod · 0.92
startValidatePrefixMethod · 0.92
hourlyCompareMethod · 0.92
EnumerateAllFunction · 0.85

Calls 4

LockMethod · 0.80
UnlockMethod · 0.80
EnumerateBlobsMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected