From bc62fa2be05be4c6786dc6c559b0146727aac3be Mon Sep 17 00:00:00 2001 From: bufdev Date: Tue, 10 Feb 2026 09:50:33 -0500 Subject: [PATCH] commit --- private/bufpkg/bufmodule/digest.go | 28 +++------------- private/pkg/cas/manifest.go | 4 +-- private/pkg/cas/storage.go | 52 ++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 private/pkg/cas/storage.go diff --git a/private/bufpkg/bufmodule/digest.go b/private/bufpkg/bufmodule/digest.go index 0e1ef5ae97..da059660bd 100644 --- a/private/bufpkg/bufmodule/digest.go +++ b/private/bufpkg/bufmodule/digest.go @@ -276,7 +276,7 @@ func getB4Digest( if err != nil { return nil, err } - casDigest, err := cas.ManifestToDigest(manifest) + casDigest, err := cas.ManifestToDigest(manifest, cas.DigestTypeShake256) if err != nil { return nil, err } @@ -372,31 +372,11 @@ func getFilesDigestForB5Digest( ctx context.Context, bucketWithStorageMatcherApplied storage.ReadBucket, ) (cas.Digest, error) { - var fileNodes []cas.FileNode - if err := storage.WalkReadObjects( + return cas.BucketToDigest( ctx, // This is extreme defensive programming. We've gone out of our way to make sure // that the bucket is already filtered, but it's just too important to mess up here. storage.FilterReadBucket(bucketWithStorageMatcherApplied, getStorageMatcher(ctx, bucketWithStorageMatcherApplied)), - "", - func(readObject storage.ReadObject) error { - digest, err := cas.NewDigestForContent(readObject) - if err != nil { - return err - } - fileNode, err := cas.NewFileNode(readObject.Path(), digest) - if err != nil { - return err - } - fileNodes = append(fileNodes, fileNode) - return nil - }, - ); err != nil { - return nil, err - } - manifest, err := cas.NewManifest(fileNodes) - if err != nil { - return nil, err - } - return cas.ManifestToDigest(manifest) + cas.DigestTypeShake256, + ) } diff --git a/private/pkg/cas/manifest.go b/private/pkg/cas/manifest.go index b292065707..9aeb9b7d0a 100644 --- a/private/pkg/cas/manifest.go +++ b/private/pkg/cas/manifest.go @@ -121,8 +121,8 @@ func ManifestToBlob(manifest Manifest) (Blob, error) { // ManifestToDigest converts the string representation of the given Manifest into a Digest. // // The Manifest is assumed to be non-nil. -func ManifestToDigest(manifest Manifest, options ...DigestOption) (Digest, error) { - return NewDigestForContent(strings.NewReader(manifest.String()), options...) +func ManifestToDigest(manifest Manifest, digestType DigestType) (Digest, error) { + return NewDigestForContent(strings.NewReader(manifest.String()), DigestWithDigestType(digestType)) } // BlobToManifest converts the given Blob representing the string representation of a Manifest into a Manifest. diff --git a/private/pkg/cas/storage.go b/private/pkg/cas/storage.go new file mode 100644 index 0000000000..43c49f9fa2 --- /dev/null +++ b/private/pkg/cas/storage.go @@ -0,0 +1,52 @@ +// Copyright 2020-2025 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cas + +import ( + "context" + + "github.com/bufbuild/buf/private/pkg/storage" +) + +// BucketToDigest converts the files in the bucket to a digest. +// +// This uses the specified DigestType for the file and manifest digests. +func BucketToDigest(ctx context.Context, bucket storage.ReadBucket, digestType DigestType) (Digest, error) { + var fileNodes []FileNode + if err := storage.WalkReadObjects( + ctx, + bucket, + "", + func(readObject storage.ReadObject) error { + digest, err := NewDigestForContent(readObject, DigestWithDigestType(digestType)) + if err != nil { + return err + } + fileNode, err := NewFileNode(readObject.Path(), digest) + if err != nil { + return err + } + fileNodes = append(fileNodes, fileNode) + return nil + }, + ); err != nil { + return nil, err + } + manifest, err := NewManifest(fileNodes) + if err != nil { + return nil, err + } + return ManifestToDigest(manifest, digestType) +}