aboutsummaryrefslogtreecommitdiff
path: root/vendor/cloud.google.com/go/storage/copy.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/cloud.google.com/go/storage/copy.go')
-rw-r--r--vendor/cloud.google.com/go/storage/copy.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/vendor/cloud.google.com/go/storage/copy.go b/vendor/cloud.google.com/go/storage/copy.go
index 16e28e3..d0a999c 100644
--- a/vendor/cloud.google.com/go/storage/copy.go
+++ b/vendor/cloud.google.com/go/storage/copy.go
@@ -25,6 +25,9 @@ import (
// CopierFrom creates a Copier that can copy src to dst.
// You can immediately call Run on the returned Copier, or
// you can configure it first.
+//
+// For Requester Pays buckets, the user project of dst is billed, unless it is empty,
+// in which case the user project of src is billed.
func (dst *ObjectHandle) CopierFrom(src *ObjectHandle) *Copier {
return &Copier{dst: dst, src: src}
}
@@ -42,7 +45,7 @@ type Copier struct {
RewriteToken string
// ProgressFunc can be used to monitor the progress of a multi-RPC copy
- // operation. If ProgressFunc is not nil and CopyFrom requires multiple
+ // operation. If ProgressFunc is not nil and copying requires multiple
// calls to the underlying service (see
// https://cloud.google.com/storage/docs/json_api/v1/objects/rewrite), then
// ProgressFunc will be invoked after each call with the number of bytes of
@@ -73,22 +76,21 @@ func (c *Copier) Run(ctx context.Context) (*ObjectAttrs, error) {
// does not cause any problems.
rawObject := c.ObjectAttrs.toRawObject("")
for {
- res, err := c.callRewrite(ctx, c.src, rawObject)
+ res, err := c.callRewrite(ctx, rawObject)
if err != nil {
return nil, err
}
if c.ProgressFunc != nil {
- c.ProgressFunc(res.TotalBytesRewritten, res.ObjectSize)
+ c.ProgressFunc(uint64(res.TotalBytesRewritten), uint64(res.ObjectSize))
}
if res.Done { // Finished successfully.
return newObject(res.Resource), nil
}
}
- return nil, nil
}
-func (c *Copier) callRewrite(ctx context.Context, src *ObjectHandle, rawObj *raw.Object) (*raw.RewriteResponse, error) {
- call := c.dst.c.raw.Objects.Rewrite(src.bucket, src.object, c.dst.bucket, c.dst.object, rawObj)
+func (c *Copier) callRewrite(ctx context.Context, rawObj *raw.Object) (*raw.RewriteResponse, error) {
+ call := c.dst.c.raw.Objects.Rewrite(c.src.bucket, c.src.object, c.dst.bucket, c.dst.object, rawObj)
call.Context(ctx).Projection("full")
if c.RewriteToken != "" {
@@ -97,6 +99,11 @@ func (c *Copier) callRewrite(ctx context.Context, src *ObjectHandle, rawObj *raw
if err := applyConds("Copy destination", c.dst.gen, c.dst.conds, call); err != nil {
return nil, err
}
+ if c.dst.userProject != "" {
+ call.UserProject(c.dst.userProject)
+ } else if c.src.userProject != "" {
+ call.UserProject(c.src.userProject)
+ }
if err := applySourceConds(c.src.gen, c.src.conds, call); err != nil {
return nil, err
}
@@ -129,6 +136,8 @@ func (dst *ObjectHandle) ComposerFrom(srcs ...*ObjectHandle) *Composer {
}
// A Composer composes source objects into a destination object.
+//
+// For Requester Pays buckets, the user project of dst is billed.
type Composer struct {
// ObjectAttrs are optional attributes to set on the destination object.
// Any attributes must be initialized before any calls on the Composer. Nil
@@ -175,6 +184,9 @@ func (c *Composer) Run(ctx context.Context) (*ObjectAttrs, error) {
if err := applyConds("ComposeFrom destination", c.dst.gen, c.dst.conds, call); err != nil {
return nil, err
}
+ if c.dst.userProject != "" {
+ call.UserProject(c.dst.userProject)
+ }
if err := setEncryptionHeaders(call.Header(), c.dst.encryptionKey, false); err != nil {
return nil, err
}