Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blob/all: disable Upload optimization when WriterOptions.ContentMD5 is set #3478

Merged
merged 1 commit into from
Aug 20, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
148 changes: 147 additions & 1 deletion blob/azureblob/testdata/TestConformance/TestUploadDownload.replay

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,16 @@ func (w *Writer) uploadAndClose(r io.Reader) (err error) {
// Shouldn't happen.
return gcerr.Newf(gcerr.Internal, nil, "blob: uploadAndClose must be the first write")
}
driverUploader, ok := w.w.(driver.Uploader)
if ok {
err = driverUploader.Upload(r)
} else {
// When ContentMD5 is being checked, we can't use Upload.
if len(w.contentMD5) > 0 {
_, err = w.ReadFrom(r)
} else {
driverUploader, ok := w.w.(driver.Uploader)
if ok {
err = driverUploader.Upload(r)
} else {
_, err = w.ReadFrom(r)
}
}
cerr := w.Close()
if err == nil && cerr != nil {
Expand Down
8 changes: 8 additions & 0 deletions blob/drivertest/drivertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,8 @@ func testUploadDownload(t *testing.T, newHarness HarnessMaker) {

const key = "blob-for-upload-download"
const contents = "up and down"
contentsMD5 := md5.Sum([]byte(contents))

ctx := context.Background()
h, err := newHarness(ctx, t)
if err != nil {
Expand Down Expand Up @@ -2251,6 +2253,12 @@ func testUploadDownload(t *testing.T, newHarness HarnessMaker) {
if bb.String() != contents {
t.Errorf("read data mismatch for key %s", key)
}

// Write another blob using Upload and ContentMD5 checking (this disables the Upload optimization).
if err := b.Upload(ctx, key, strings.NewReader(contents), &blob.WriterOptions{ContentMD5: contentsMD5[:], ContentType: "text"}); err != nil {
t.Fatal(err)
}
defer b.Delete(ctx, key)
}

// testKeys tests a variety of weird keys.
Expand Down
Loading
Loading