Skip to content

Commit f4dd7c4

Browse files
committed
blob/all: disable Upload optimization when WriterOptions.ContentMD5 is set
1 parent 7a096fb commit f4dd7c4

File tree

314 files changed

+13788
-13055
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

314 files changed

+13788
-13055
lines changed

blob/azureblob/testdata/TestConformance/TestUploadDownload.replay

Lines changed: 147 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blob/blob.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,16 @@ func (w *Writer) uploadAndClose(r io.Reader) (err error) {
514514
// Shouldn't happen.
515515
return gcerr.Newf(gcerr.Internal, nil, "blob: uploadAndClose must be the first write")
516516
}
517-
driverUploader, ok := w.w.(driver.Uploader)
518-
if ok {
519-
err = driverUploader.Upload(r)
520-
} else {
517+
// When ContentMD5 is being checked, we can't use Upload.
518+
if len(w.contentMD5) > 0 {
521519
_, err = w.ReadFrom(r)
520+
} else {
521+
driverUploader, ok := w.w.(driver.Uploader)
522+
if ok {
523+
err = driverUploader.Upload(r)
524+
} else {
525+
_, err = w.ReadFrom(r)
526+
}
522527
}
523528
cerr := w.Close()
524529
if err == nil && cerr != nil {

blob/drivertest/drivertest.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,6 +2223,8 @@ func testUploadDownload(t *testing.T, newHarness HarnessMaker) {
22232223

22242224
const key = "blob-for-upload-download"
22252225
const contents = "up and down"
2226+
contentsMD5 := md5.Sum([]byte(contents))
2227+
22262228
ctx := context.Background()
22272229
h, err := newHarness(ctx, t)
22282230
if err != nil {
@@ -2251,6 +2253,12 @@ func testUploadDownload(t *testing.T, newHarness HarnessMaker) {
22512253
if bb.String() != contents {
22522254
t.Errorf("read data mismatch for key %s", key)
22532255
}
2256+
2257+
// Write another blob using Upload and ContentMD5 checking (this disables the Upload optimization).
2258+
if err := b.Upload(ctx, key, strings.NewReader(contents), &blob.WriterOptions{ContentMD5: contentsMD5[:], ContentType: "text"}); err != nil {
2259+
t.Fatal(err)
2260+
}
2261+
defer b.Delete(ctx, key)
22542262
}
22552263

22562264
// testKeys tests a variety of weird keys.

0 commit comments

Comments
 (0)