@@ -6,32 +6,36 @@ import (
66 "github.com/aws/aws-sdk-go/aws"
77 "github.com/aws/aws-sdk-go/service/s3"
88 "github.com/pkg/errors"
9+ "github.com/viant/afs/option"
910 "github.com/viant/afs/storage"
1011 "path"
1112 "strings"
1213)
1314
1415func (s * storager ) Copy (ctx context.Context , sourcePath , destBucket , destPath string , options ... storage.Option ) error {
15-
1616 sourcePath = strings .Trim (sourcePath , "/" )
1717 destPath = strings .Trim (destPath , "/" )
18- infoList , err := s .List (ctx , sourcePath , options ... )
19- if err != nil {
20- return errors .Wrapf (err , "unable list copy source: gs://%v/%v" , s .bucket , sourcePath )
21- }
22- if len (infoList ) == 0 {
23- return fmt .Errorf ("%v: not found" , sourcePath )
24- }
25- for i := 1 ; i < len (infoList ); i ++ {
26- name := infoList [i ].Name ()
27- if err = s .Copy (ctx , path .Join (sourcePath , name ), destBucket , path .Join (destPath , name ), options ... ); err != nil {
18+ _ , err := s .get (ctx , sourcePath , options )
19+ if isNotFound (err ) {
20+ objectOpt := & option.ObjectKind {}
21+ if _ , ok := option .Assign (options , objectOpt ); ok && objectOpt .File {
2822 return err
2923 }
30- }
31- if infoList [0 ].IsDir () {
24+ infoList , err := s .List (ctx , sourcePath )
25+ if err != nil {
26+ return err
27+ }
28+ if len (infoList ) == 0 {
29+ return fmt .Errorf ("%v: not found" , sourcePath )
30+ }
31+ for i := 1 ; i < len (infoList ); i ++ {
32+ name := infoList [i ].Name ()
33+ if err = s .Move (ctx , path .Join (sourcePath , name ), destBucket , path .Join (destPath , name )); err != nil {
34+ return err
35+ }
36+ }
3237 return nil
3338 }
34-
3539 _ , err = s .S3 .CopyObjectWithContext (ctx , & s3.CopyObjectInput {
3640 CopySource : aws .String (s .bucket + "/" + sourcePath ),
3741 Key : & destPath ,
0 commit comments