(ctx context.Context, rep repo.DirectRepositoryWriter)
| 40 | } |
| 41 | |
| 42 | func (c *commandIndexRecover) run(ctx context.Context, rep repo.DirectRepositoryWriter) error { |
| 43 | c.svc.dangerousCommand() |
| 44 | |
| 45 | var ( |
| 46 | processedBlobCount atomic.Int32 |
| 47 | recoveredContentCount atomic.Int32 |
| 48 | ) |
| 49 | |
| 50 | defer func() { |
| 51 | if recoveredContentCount.Load() == 0 { |
| 52 | log(ctx).Info("No contents recovered.") |
| 53 | return |
| 54 | } |
| 55 | |
| 56 | if !c.commit { |
| 57 | log(ctx).Infof("Found %v contents to recover from %v blobs, but not committed. Re-run with --commit", recoveredContentCount.Load(), processedBlobCount.Load()) |
| 58 | } else { |
| 59 | log(ctx).Infof("Recovered %v contents from %v.", recoveredContentCount.Load(), processedBlobCount.Load()) |
| 60 | } |
| 61 | }() |
| 62 | |
| 63 | if c.deleteIndexes { |
| 64 | if err := rep.BlobReader().ListBlobs(ctx, indexblob.V0IndexBlobPrefix, func(bm blob.Metadata) error { |
| 65 | if c.commit { |
| 66 | log(ctx).Infof("deleting old index blob: %v", bm.BlobID) |
| 67 | return errors.Wrap(rep.BlobStorage().DeleteBlob(ctx, bm.BlobID), "error deleting index blob") |
| 68 | } |
| 69 | |
| 70 | log(ctx).Infof("would delete old index: %v (pass --commit to approve)", bm.BlobID) |
| 71 | return nil |
| 72 | }); err != nil { |
| 73 | return errors.Wrap(err, "error deleting old indexes") |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | if len(c.blobIDs) == 0 { |
| 78 | var prefixes []blob.ID |
| 79 | |
| 80 | if len(c.blobPrefixes) > 0 { |
| 81 | for _, p := range c.blobPrefixes { |
| 82 | prefixes = append(prefixes, blob.ID(p)) |
| 83 | } |
| 84 | } else { |
| 85 | prefixes = content.PackBlobIDPrefixes |
| 86 | } |
| 87 | |
| 88 | return c.recoverIndexesFromAllPacks(ctx, rep, prefixes, &processedBlobCount, &recoveredContentCount) |
| 89 | } |
| 90 | |
| 91 | for _, packFile := range c.blobIDs { |
| 92 | if err := c.recoverIndexFromSinglePackFile(ctx, rep, blob.ID(packFile), 0, &processedBlobCount, &recoveredContentCount); err != nil && !c.ignoreErrors { |
| 93 | return errors.Wrapf(err, "error recovering index from %v", packFile) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return nil |
| 98 | } |
| 99 |
nothing calls this directly
no test coverage detected