Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions private/bufpkg/bufmodule/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
)
}
4 changes: 2 additions & 2 deletions private/pkg/cas/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
52 changes: 52 additions & 0 deletions private/pkg/cas/storage.go
Original file line number Diff line number Diff line change
@@ -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)
}