Skip to content

Commit

Permalink
combine write and update to one request
Browse files Browse the repository at this point in the history
Signed-off-by: Babis Kiosidis <ckiosidis@gmail.com>
  • Loading branch information
ckiosidis committed Jul 14, 2022
1 parent 9c3f5f9 commit 6237dc1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions google/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,25 @@ func (c *Container) Put(name string, r io.Reader, size int64, metadata map[strin
}

w := obj.NewWriter(c.ctx)
w.ObjectAttrs.Metadata = merge(w.ObjectAttrs.Metadata, mdPrepped)
if _, err := io.Copy(w, r); err != nil {
return nil, err
}
w.Close()

attr, err := obj.Update(c.ctx, storage.ObjectAttrsToUpdate{Metadata: mdPrepped})
if err != nil {
if err = w.Close(); err != nil {
return nil, err
}

return c.convertToStowItem(attr)
return c.convertToStowItem(w.Attrs())
}

func merge(metadata ...map[string]string) map[string]string {
res := map[string]string{}
for _, mt := range metadata {
for k, v := range mt {
res[k] = v
}
}
return res
}

func (c *Container) convertToStowItem(attr *storage.ObjectAttrs) (stow.Item, error) {
Expand Down

0 comments on commit 6237dc1

Please sign in to comment.