IteratePacks invokes the provided callback for all pack blobs.
(ctx context.Context, options IteratePackOptions, callback IteratePacksCallback)
| 189 | |
| 190 | // IteratePacks invokes the provided callback for all pack blobs. |
| 191 | func (bm *WriteManager) IteratePacks(ctx context.Context, options IteratePackOptions, callback IteratePacksCallback) error { |
| 192 | packUsage := map[blob.ID]*PackInfo{} |
| 193 | |
| 194 | if err := bm.IterateContents( |
| 195 | ctx, |
| 196 | IterateOptions{ |
| 197 | IncludeDeleted: options.IncludePacksWithOnlyDeletedContent, |
| 198 | }, |
| 199 | func(ci Info) error { |
| 200 | if !options.matchesBlob(ci.PackBlobID) { |
| 201 | return nil |
| 202 | } |
| 203 | |
| 204 | pi := packUsage[ci.PackBlobID] |
| 205 | if pi == nil { |
| 206 | pi = &PackInfo{PackID: ci.PackBlobID} |
| 207 | packUsage[ci.PackBlobID] = pi |
| 208 | } |
| 209 | pi.ContentCount++ |
| 210 | pi.TotalSize += int64(ci.PackedLength) |
| 211 | if options.IncludeContentInfos { |
| 212 | pi.ContentInfos = append(pi.ContentInfos, ci) |
| 213 | } |
| 214 | return nil |
| 215 | }); err != nil { |
| 216 | return errors.Wrap(err, "error iterating contents") |
| 217 | } |
| 218 | |
| 219 | for _, v := range packUsage { |
| 220 | if err := callback(*v); err != nil { |
| 221 | return err |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | return nil |
| 226 | } |
| 227 | |
| 228 | // IterateUnreferencedPacks returns the list of unreferenced storage blobs. |
| 229 | func (bm *WriteManager) IterateUnreferencedPacks(ctx context.Context, blobPrefixes []blob.ID, parallelism int, callback func(blob.Metadata) error) error { |
no test coverage detected