MCPcopy Create free account
hub / github.com/google/go-cloud / Copy

Method Copy

blob/blob.go:1251–1272  ·  view source on GitHub ↗

Copy the blob stored at srcKey to dstKey. A nil CopyOptions is treated the same as the zero value. If the source blob does not exist, Copy returns an error for which gcerrors.Code will return gcerrors.NotFound. If the destination blob already exists, it is overwritten.

(ctx context.Context, dstKey, srcKey string, opts *CopyOptions)

Source from the content-addressed store, hash-verified

1249//
1250// If the destination blob already exists, it is overwritten.
1251func (b *Bucket) Copy(ctx context.Context, dstKey, srcKey string, opts *CopyOptions) (err error) {
1252 if !utf8.ValidString(srcKey) {
1253 return gcerr.Newf(gcerr.InvalidArgument, nil, "blob: Copy srcKey must be a valid UTF-8 string: %q", srcKey)
1254 }
1255 if !utf8.ValidString(dstKey) {
1256 return gcerr.Newf(gcerr.InvalidArgument, nil, "blob: Copy dstKey must be a valid UTF-8 string: %q", dstKey)
1257 }
1258 if opts == nil {
1259 opts = &CopyOptions{}
1260 }
1261 dopts := &driver.CopyOptions{
1262 BeforeCopy: opts.BeforeCopy,
1263 }
1264 b.mu.RLock()
1265 defer b.mu.RUnlock()
1266 if b.closed {
1267 return errClosed
1268 }
1269 ctx, span := b.tracer.Start(ctx, "Copy")
1270 defer func() { b.tracer.End(ctx, span, err) }()
1271 return wrapError(b.b, b.b.Copy(ctx, dstKey, srcKey, dopts), fmt.Sprintf("%s -> %s", srcKey, dstKey))
1272}
1273
1274// Delete deletes the blob stored at key.
1275//

Callers 2

TestErrorsAreWrappedFunction · 0.95
TestBucketIsClosedFunction · 0.95

Calls 5

NewfFunction · 0.92
StartMethod · 0.80
EndMethod · 0.80
wrapErrorFunction · 0.70
CopyMethod · 0.65

Tested by 2

TestErrorsAreWrappedFunction · 0.76
TestBucketIsClosedFunction · 0.76