(ctx context.Context, st blob.Storage, prefixes []string)
| 80 | } |
| 81 | |
| 82 | func (c *commandRepositoryRepair) recoverFormatBlob(ctx context.Context, st blob.Storage, prefixes []string) error { |
| 83 | errSuccess := errors.New("success") |
| 84 | |
| 85 | for _, prefix := range prefixes { |
| 86 | err := st.ListBlobs(ctx, blob.ID(prefix), func(bi blob.Metadata) error { |
| 87 | log(ctx).Infof("looking for replica of format blob in %v...", bi.BlobID) |
| 88 | |
| 89 | if b, err := format.RecoverFormatBlob(ctx, st, bi.BlobID, bi.Length); err == nil { |
| 90 | if !c.repairDryRun { |
| 91 | if puterr := st.PutBlob(ctx, format.KopiaRepositoryBlobID, gather.FromSlice(b), blob.PutOptions{}); puterr != nil { |
| 92 | return errors.Wrap(puterr, "error writing format blob") |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | log(ctx).Infof("recovered replica block from %v", bi.BlobID) |
| 97 | |
| 98 | return errSuccess |
| 99 | } |
| 100 | |
| 101 | return nil |
| 102 | }) |
| 103 | |
| 104 | switch { |
| 105 | case err == nil: |
| 106 | // do nothing |
| 107 | case errors.Is(err, errSuccess): |
| 108 | return nil |
| 109 | default: |
| 110 | return errors.Wrap(err, "unexpected error when listing blobs") |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return errors.New("could not find a replica of a format blob") |
| 115 | } |
no test coverage detected