Skip to content

Commit

Permalink
blob/all: disable Upload optimization when WriterOptions.ContentMD5 i…
Browse files Browse the repository at this point in the history
…s set
  • Loading branch information
vangent committed Aug 20, 2024
1 parent 7a096fb commit f4dd7c4
Show file tree
Hide file tree
Showing 314 changed files with 13,788 additions and 13,055 deletions.
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

0 comments on commit f4dd7c4

Please sign in to comment.