blobExists returns true iff repo contains a blob with digest, and if so, also its size. If the destination does not contain the blob, or it is unknown, blobExists ordinarily returns (false, -1, nil); it returns a non-nil error only on an unexpected failure.
(ctx context.Context, repo reference.Named, digest digest.Digest, extraScope *authScope)
| 231 | // If the destination does not contain the blob, or it is unknown, blobExists ordinarily returns (false, -1, nil); |
| 232 | // it returns a non-nil error only on an unexpected failure. |
| 233 | func (d *dockerImageDestination) blobExists(ctx context.Context, repo reference.Named, digest digest.Digest, extraScope *authScope) (bool, int64, error) { |
| 234 | if err := digest.Validate(); err != nil { // Make sure digest.String() does not contain any unexpected characters |
| 235 | return false, -1, err |
| 236 | } |
| 237 | checkPath := fmt.Sprintf(blobsPath, reference.Path(repo), digest.String()) |
| 238 | logrus.Debugf("Checking %s", checkPath) |
| 239 | res, err := d.c.makeRequest(ctx, http.MethodHead, checkPath, nil, nil, v2Auth, extraScope) |
| 240 | if err != nil { |
| 241 | return false, -1, err |
| 242 | } |
| 243 | defer res.Body.Close() |
| 244 | switch res.StatusCode { |
| 245 | case http.StatusOK: |
| 246 | size, err := getBlobSize(res) |
| 247 | if err != nil { |
| 248 | return false, -1, fmt.Errorf("determining size of blob %s in %s: %w", digest, repo.Name(), err) |
| 249 | } |
| 250 | logrus.Debugf("... already exists") |
| 251 | return true, size, nil |
| 252 | case http.StatusUnauthorized: |
| 253 | logrus.Debugf("... not authorized") |
| 254 | return false, -1, fmt.Errorf("checking whether a blob %s exists in %s: %w", digest, repo.Name(), registryHTTPResponseToError(res)) |
| 255 | case http.StatusNotFound: |
| 256 | logrus.Debugf("... not present") |
| 257 | return false, -1, nil |
| 258 | default: |
| 259 | return false, -1, fmt.Errorf("checking whether a blob %s exists in %s: %w", digest, repo.Name(), registryHTTPResponseToError(res)) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | // mountBlob tries to mount blob srcDigest from srcRepo to the current destination. |
| 264 | func (d *dockerImageDestination) mountBlob(ctx context.Context, srcRepo reference.Named, srcDigest digest.Digest, extraScope *authScope) error { |
no test coverage detected