CopyObject copy specified object from srcKey to dstKey.
(ctx context.Context, srcBucket, srcKey, dstBucket, dstKey string, meta map[string]string)
| 389 | |
| 390 | // CopyObject copy specified object from srcKey to dstKey. |
| 391 | func (b *s3Backend) CopyObject(ctx context.Context, srcBucket, srcKey, dstBucket, dstKey string, meta map[string]string) (result gofakes3.CopyObjectResult, err error) { |
| 392 | if srcBucket == dstBucket && srcKey == dstKey { |
| 393 | //TODO: update meta |
| 394 | return result, nil |
| 395 | } |
| 396 | |
| 397 | srcB, err := getBucketByName(srcBucket) |
| 398 | if err != nil { |
| 399 | return result, err |
| 400 | } |
| 401 | srcBucketPath := srcB.Path |
| 402 | |
| 403 | srcFp := path.Join(srcBucketPath, srcKey) |
| 404 | fmeta, _ := op.GetNearestMeta(srcFp) |
| 405 | srcNode, err := fs.Get(context.WithValue(ctx, conf.MetaKey, fmeta), srcFp, &fs.GetArgs{}) |
| 406 | |
| 407 | c, err := b.GetObject(ctx, srcBucket, srcKey, nil) |
| 408 | if err != nil { |
| 409 | return |
| 410 | } |
| 411 | defer func() { |
| 412 | _ = c.Contents.Close() |
| 413 | }() |
| 414 | |
| 415 | for k, v := range c.Metadata { |
| 416 | if _, found := meta[k]; !found && k != "X-Amz-Acl" { |
| 417 | meta[k] = v |
| 418 | } |
| 419 | } |
| 420 | if _, ok := meta["mtime"]; !ok { |
| 421 | meta["mtime"] = swift.TimeToFloatString(srcNode.ModTime()) |
| 422 | } |
| 423 | |
| 424 | _, err = b.PutObject(ctx, dstBucket, dstKey, meta, c.Contents, c.Size) |
| 425 | if err != nil { |
| 426 | return |
| 427 | } |
| 428 | |
| 429 | return gofakes3.CopyObjectResult{ |
| 430 | ETag: `"` + hex.EncodeToString(c.Hash) + `"`, |
| 431 | LastModified: gofakes3.NewContentTime(srcNode.ModTime()), |
| 432 | }, nil |
| 433 | } |
no test coverage detected