Enable MD5 check on GCS driver

Apparently you can upload 0-size content wihtout GCS reportin any errors
back to you.

This is something a lot of our users experienced and reported. See here
for at least one example:
github.com/distribution/distribution/issues/3018

This sets tbe MD5 sum on the uploaded content which should rectify
things according to the docs:
https://pkg.go.dev/cloud.google.com/go/storage#ObjectAttrs

Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
This commit is contained in:
Milos Gajdos 2025-02-28 07:20:48 -08:00
parent d9b0802d81
commit e20645c050
No known key found for this signature in database

View File

@ -14,6 +14,7 @@ package gcs
import ( import (
"bytes" "bytes"
"context" "context"
"crypto/md5"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -425,6 +426,10 @@ func (d *driver) putContent(ctx context.Context, obj *storage.ObjectHandle, cont
if _, err := bytes.NewReader(content).WriteTo(wc); err != nil { if _, err := bytes.NewReader(content).WriteTo(wc); err != nil {
return err return err
} }
h := md5.New()
h.Write(content)
wc.MD5 = h.Sum(nil)
return wc.Close() return wc.Close()
} }