From e3fd3a0b3a85b97703b2cac74bbc11c0a149cbdf Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Sat, 18 Nov 2023 21:35:44 -0800 Subject: [PATCH] snowball: Support advanced put object options --- api-put-object.go | 27 +++++++++++++++++++++++++++ api-putobject-snowball.go | 15 +++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/api-put-object.go b/api-put-object.go index bbd8924e28..1216006a5b 100644 --- a/api-put-object.go +++ b/api-put-object.go @@ -21,6 +21,7 @@ import ( "bytes" "context" "encoding/base64" + "encoding/gob" "errors" "fmt" "hash/crc32" @@ -99,6 +100,32 @@ type PutObjectOptions struct { customHeaders http.Header } +type wrapPutObjectOptions PutObjectOptions + +func (o PutObjectOptions) MarshalBinary() ([]byte, error) { + // Wrap struct + w := wrapPutObjectOptions(o) + // use default gob encoder + var buf bytes.Buffer + enc := gob.NewEncoder(&buf) + if err := enc.Encode(w); err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +func (oi *PutObjectOptions) UnmarshalBinary(data []byte) error { + w := wrapPutObjectOptions{} + // Use default gob decoder + reader := bytes.NewReader(data) + dec := gob.NewDecoder(reader) + if err := dec.Decode(&w); err != nil { + return err + } + *oi = PutObjectOptions(w) + return nil +} + // SetMatchETag if etag matches while PUT MinIO returns an error // this is a MinIO specific extension to support optimistic locking // semantics. diff --git a/api-putobject-snowball.go b/api-putobject-snowball.go index 983ed67449..b85127ad2a 100644 --- a/api-putobject-snowball.go +++ b/api-putobject-snowball.go @@ -22,6 +22,7 @@ import ( "bufio" "bytes" "context" + "encoding/base64" "fmt" "io" "os" @@ -70,6 +71,12 @@ type SnowballObject struct { // Exactly 'Size' number of bytes must be provided. Content io.Reader + // VersionID of the object; if empty, a new versionID will be generated + VersionID string + + // AdvancedMetadata contains more information about the current PutObject operation + AdvancedMetadata []byte + // Close will be called when an object has finished processing. // Note that if PutObjectsSnowball returns because of an error, // objects not consumed from the input will NOT have been closed. @@ -181,6 +188,14 @@ objectLoop: header.ModTime = time.Now().UTC() } + header.PAXRecords = make(map[string]string) + if obj.VersionID != "" { + header.PAXRecords["minio.versionId"] = obj.VersionID + } + if obj.AdvancedMetadata != nil { + header.PAXRecords["minio.internal"] = base64.StdEncoding.EncodeToString(obj.AdvancedMetadata) + } + if err := t.WriteHeader(&header); err != nil { closeObj() return err