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