MCPcopy Index your code
hub / github.com/peak/s5cmd / validateCopyCommand

Function validateCopyCommand

command/cp.go:996–1048  ·  view source on GitHub ↗
(c *cli.Context)

Source from the content-addressed store, hash-verified

994}
995
996func validateCopyCommand(c *cli.Context) error {
997 if c.Args().Len() != 2 {
998 return fmt.Errorf("expected source and destination arguments")
999 }
1000
1001 ctx := c.Context
1002 src := c.Args().Get(0)
1003 dst := c.Args().Get(1)
1004
1005 srcurl, err := url.New(src, url.WithVersion(c.String("version-id")),
1006 url.WithRaw(c.Bool("raw")))
1007 if err != nil {
1008 return err
1009 }
1010
1011 dsturl, err := url.New(dst, url.WithRaw(c.Bool("raw")))
1012 if err != nil {
1013 return err
1014 }
1015
1016 // wildcard destination doesn't mean anything
1017 if dsturl.IsWildcard() {
1018 return fmt.Errorf("target %q can not contain glob characters", dst)
1019 }
1020
1021 // we don't operate on S3 prefixes for copy and delete operations.
1022 if srcurl.IsBucket() || srcurl.IsPrefix() {
1023 return fmt.Errorf("source argument must contain wildcard character")
1024 }
1025
1026 // 'cp dir/* s3://bucket/prefix': expect a trailing slash to avoid any
1027 // surprises.
1028 if srcurl.IsWildcard() && dsturl.IsRemote() && !dsturl.IsPrefix() && !dsturl.IsBucket() {
1029 return fmt.Errorf("target %q must be a bucket or a prefix", dsturl)
1030 }
1031
1032 if err := checkVersinoningURLRemote(srcurl); err != nil {
1033 return err
1034 }
1035
1036 if err := checkVersioningWithGoogleEndpoint(c); err != nil {
1037 return err
1038 }
1039
1040 switch {
1041 case srcurl.Type == dsturl.Type:
1042 return validateCopy(srcurl, dsturl)
1043 case dsturl.IsRemote():
1044 return validateUpload(ctx, srcurl, dsturl, NewStorageOpts(c))
1045 default:
1046 return nil
1047 }
1048}
1049
1050func validateCopy(srcurl, dsturl *url.URL) error {
1051 if srcurl.IsRemote() || dsturl.IsRemote() {

Callers 2

NewCopyCommandFunction · 0.85
NewSyncCommandFunction · 0.85

Calls 14

NewFunction · 0.92
WithVersionFunction · 0.92
WithRawFunction · 0.92
validateCopyFunction · 0.85
validateUploadFunction · 0.85
NewStorageOptsFunction · 0.85
IsWildcardMethod · 0.80
IsBucketMethod · 0.80
IsPrefixMethod · 0.80
IsRemoteMethod · 0.80

Tested by

no test coverage detected