-
Notifications
You must be signed in to change notification settings - Fork 17
/
copy.go
35 lines (26 loc) · 952 Bytes
/
copy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (C) 2022 Storj Labs, Inc.
// See LICENSE for copying information.
package uplink
import (
"context"
"github.com/zeebo/errs"
"storj.io/uplink/private/metaclient"
)
// CopyObjectOptions options for CopyObject method.
type CopyObjectOptions struct {
// may contain additional options in the future
}
// CopyObject atomically copies object to a different bucket or/and key.
func (project *Project) CopyObject(ctx context.Context, oldBucket, oldKey, newBucket, newKey string, options *CopyObjectOptions) (_ *Object, err error) {
defer mon.Task()(&ctx)(&err)
db, err := dialMetainfoDB(ctx, project)
if err != nil {
return nil, packageError.Wrap(err)
}
defer func() { err = errs.Combine(err, db.Close()) }()
obj, err := db.CopyObject(ctx, oldBucket, oldKey, nil, newBucket, newKey, metaclient.CopyObjectOptions{})
if err != nil {
return nil, convertKnownErrors(err, oldBucket, oldKey)
}
return convertObject(obj), nil
}