Skip to content

Commit

Permalink
snowball: Support advanced put object options
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis Elleuch committed Nov 19, 2023
1 parent 6eebdd6 commit e3fd3a0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
27 changes: 27 additions & 0 deletions api-put-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"bytes"
"context"
"encoding/base64"
"encoding/gob"
"errors"
"fmt"
"hash/crc32"
Expand Down Expand Up @@ -99,6 +100,32 @@ type PutObjectOptions struct {
customHeaders http.Header
}

type wrapPutObjectOptions PutObjectOptions

func (o PutObjectOptions) MarshalBinary() ([]byte, error) {

Check failure on line 105 in api-put-object.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.19.x and ubuntu-latest

exported: exported method PutObjectOptions.MarshalBinary should have comment or be unexported (revive)

Check failure on line 105 in api-put-object.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.21.x and ubuntu-latest

exported: exported method PutObjectOptions.MarshalBinary should have comment or be unexported (revive)
// 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 {

Check failure on line 117 in api-put-object.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.19.x and ubuntu-latest

exported: exported method PutObjectOptions.UnmarshalBinary should have comment or be unexported (revive)

Check failure on line 117 in api-put-object.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.21.x and ubuntu-latest

receiver-naming: receiver name oi should be consistent with previous receiver name o for PutObjectOptions (revive)
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.
Expand Down
15 changes: 15 additions & 0 deletions api-putobject-snowball.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"bufio"
"bytes"
"context"
"encoding/base64"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e3fd3a0

Please sign in to comment.