getB5Digest computes a b5 Digest for the given set of module files and dependencies. A Digest is a composite digest of all Module Files, and all Module dependencies. All Files are added to a cas.Manifest, which is then turned into a cas.Digest. The file cas.Digest, along with all Digests of the de
( ctx context.Context, bucketWithStorageMatcherApplied storage.ReadBucket, depDigests []Digest, )
| 329 | // |
| 330 | // Note that the order of the depDigests does not matter - they are sorted within this function. |
| 331 | func getB5DigestForBucketAndDepDigests( |
| 332 | ctx context.Context, |
| 333 | bucketWithStorageMatcherApplied storage.ReadBucket, |
| 334 | depDigests []Digest, |
| 335 | ) (Digest, error) { |
| 336 | // First, compute the shake256 cas.Digest of the files. This will include a |
| 337 | // sorted list of file names and their digests. |
| 338 | filesDigest, err := getFilesDigestForB5Digest(ctx, bucketWithStorageMatcherApplied) |
| 339 | if err != nil { |
| 340 | return nil, err |
| 341 | } |
| 342 | if filesDigest.Type() != cas.DigestTypeShake256 { |
| 343 | return nil, syserror.Newf("trying to compute b5 Digest with files digest of type %v", filesDigest.Type()) |
| 344 | } |
| 345 | // Next, we get the b5 digests of all the dependencies and sort their string representations. |
| 346 | depDigestStrings, err := xslices.MapError( |
| 347 | depDigests, |
| 348 | func(digest Digest) (string, error) { |
| 349 | if digest.Type() != DigestTypeB5 { |
| 350 | // Even if the buf.lock file had a b4 digest, we should still end up retrieving the b5 |
| 351 | // digest from the BSR, we should never have a b5 digest here. |
| 352 | return "", syserror.Newf("trying to compute b5 Digest with dependency digest of type %v", digest.Type()) |
| 353 | } |
| 354 | return digest.String(), nil |
| 355 | }, |
| 356 | ) |
| 357 | if err != nil { |
| 358 | return nil, err |
| 359 | } |
| 360 | sort.Strings(depDigestStrings) |
| 361 | // Now, place the file digest first, then the sorted dependency digests afterwards. |
| 362 | digestStrings := append([]string{filesDigest.String()}, depDigestStrings...) |
| 363 | // Join these strings together with newlines, and make a new shake256 digest. |
| 364 | digestOfDigests, err := cas.NewDigestForContent(cas.DigestTypeShake256, strings.NewReader(strings.Join(digestStrings, "\n"))) |
| 365 | if err != nil { |
| 366 | return nil, err |
| 367 | } |
| 368 | // The resulting digest is a b5 digest. |
| 369 | return NewDigest(DigestTypeB5, digestOfDigests) |
| 370 | } |
| 371 | |
| 372 | // The bucket should have already been filtered to just module files. |
| 373 | func getFilesDigestForB5Digest( |
no test coverage detected
searching dependent graphs…