Skip to content

Commit bc051b6

Browse files
committed
minor fixes
1 parent 1e5a627 commit bc051b6

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

google-api-go-generator/gen.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,10 @@ func (meth *Method) generateCode() {
22832283
if meth.supportsMediaUpload() && meth.api.Name == "storage" {
22842284
comment = "Set auto checksum in case of a single chunk upload if enabled."
22852285
p("%s", asComment("", comment))
2286-
pn("if c.mediaInfo_ != nil {")
2286+
pn("if c.object != nil &&")
2287+
pn(" c.mediaInfo_ != nil &&")
2288+
pn(" c.mediaInfo_.ChecksumEnabled() &&")
2289+
pn(` c.mediaInfo_.UploadType() == "multipart" {`)
22872290
pn(" c.object.Crc32c = c.mediaInfo_.GetAutoChecksum()")
22882291
pn("}")
22892292
}

internal/gensupport/media.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,19 @@ func (mi *MediaInfo) UploadType() string {
198198
return "resumable"
199199
}
200200

201-
// GetAutoChecksum returns the computed auto checksum (if enabled)
202-
// for single-chunk resumable uploads.
201+
// ChecksumEnabled returns true if both buffering is used and
202+
// enableAutoChecksum flag is set to true.
203+
func (mi *MediaInfo) ChecksumEnabled() bool {
204+
return mi.buffer != nil && mi.buffer.enableAutoChecksum
205+
}
206+
207+
// GetAutoChecksum returns the computed auto checksum from buffer (if enabled).
208+
// Make sure whole data is written and read from the buffer before calling this
209+
// function to get correct checksum of the data.
203210
func (mi *MediaInfo) GetAutoChecksum() string {
204-
if mi.buffer.enableAutoChecksum &&
205-
mi.buffer != nil &&
206-
mi.singleChunk {
207-
return encodeUint32(mi.buffer.fullObjectChecksum + 1)
211+
if mi.buffer != nil &&
212+
mi.buffer.enableAutoChecksum {
213+
return encodeUint32(mi.buffer.fullObjectChecksum)
208214
}
209215
return ""
210216
}

storage/v1/storage-gen.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)