fix: multipart replication with single part objects (#20895)

x-amz-checksum-algorithm is not set, causing all multipart single-part objects
to fail to replicate going via sftp/FTP uploads.
This commit is contained in:
Klaus Post
2025-02-05 15:06:02 -08:00
committed by GitHub
parent 7fa3e39f85
commit b8dde47d4e
9 changed files with 79 additions and 49 deletions

View File

@@ -203,6 +203,24 @@ func (c ChecksumType) String() string {
return "invalid"
}
// StringFull returns the type and all flags as a string.
func (c ChecksumType) StringFull() string {
out := []string{c.String()}
if c.Is(ChecksumMultipart) {
out = append(out, "MULTIPART")
}
if c.Is(ChecksumIncludesMultipart) {
out = append(out, "INCLUDESMP")
}
if c.Is(ChecksumTrailing) {
out = append(out, "TRAILING")
}
if c.Is(ChecksumFullObject) {
out = append(out, "FULLOBJ")
}
return strings.Join(out, "|")
}
// FullObjectRequested will return if the checksum type indicates full object checksum was requested.
func (c ChecksumType) FullObjectRequested() bool {
return c&(ChecksumFullObject) == ChecksumFullObject || c.Is(ChecksumCRC64NVME)
@@ -263,7 +281,8 @@ func NewChecksumFromData(t ChecksumType, data []byte) *Checksum {
}
// ReadCheckSums will read checksums from b and return them.
func ReadCheckSums(b []byte, part int) map[string]string {
// Returns whether this is (part of) a multipart checksum.
func ReadCheckSums(b []byte, part int) (cs map[string]string, isMP bool) {
res := make(map[string]string, 1)
for len(b) > 0 {
t, n := binary.Uvarint(b)
@@ -277,9 +296,11 @@ func ReadCheckSums(b []byte, part int) map[string]string {
if length == 0 || len(b) < length {
break
}
cs := base64.StdEncoding.EncodeToString(b[:length])
b = b[length:]
if typ.Is(ChecksumMultipart) {
isMP = true
t, n := binary.Uvarint(b)
if n < 0 {
break
@@ -317,7 +338,7 @@ func ReadCheckSums(b []byte, part int) map[string]string {
if len(res) == 0 {
res = nil
}
return res
return res, isMP
}
// ReadPartCheckSums will read all part checksums from b and return them.