github.com/jfrog/jfrog-cli-core/v2@v2.51.0/artifactory/commands/generic/copy.go (about) 1 package generic 2 3 import ( 4 "errors" 5 6 "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" 7 "github.com/jfrog/jfrog-cli-core/v2/common/spec" 8 "github.com/jfrog/jfrog-client-go/artifactory/services" 9 "github.com/jfrog/jfrog-client-go/utils/log" 10 ) 11 12 type CopyCommand struct { 13 GenericCommand 14 threads int 15 } 16 17 func NewCopyCommand() *CopyCommand { 18 return &CopyCommand{GenericCommand: *NewGenericCommand()} 19 } 20 21 func (cc *CopyCommand) Threads() int { 22 return cc.threads 23 } 24 25 func (cc *CopyCommand) SetThreads(threads int) *CopyCommand { 26 cc.threads = threads 27 return cc 28 } 29 30 func (cc *CopyCommand) CommandName() string { 31 return "rt_copy" 32 } 33 34 // Copies the artifacts using the specified move pattern. 35 func (cc *CopyCommand) Run() error { 36 // Create Service Manager: 37 servicesManager, err := utils.CreateServiceManagerWithThreads(cc.serverDetails, cc.dryRun, cc.threads, cc.retries, cc.retryWaitTimeMilliSecs) 38 if err != nil { 39 return err 40 } 41 42 var errorOccurred = false 43 var copyParamsArray []services.MoveCopyParams 44 // Create CopyParams for all File-Spec groups. 45 for i := 0; i < len(cc.spec.Files); i++ { 46 copyParams, err := getCopyParams(cc.spec.Get(i)) 47 if err != nil { 48 errorOccurred = true 49 log.Error(err) 50 continue 51 } 52 copyParamsArray = append(copyParamsArray, copyParams) 53 } 54 55 // Perform copy. 56 totalCopied, totalFailed, err := servicesManager.Copy(copyParamsArray...) 57 if err != nil { 58 errorOccurred = true 59 log.Error(err) 60 } 61 cc.result.SetSuccessCount(totalCopied) 62 cc.result.SetFailCount(totalFailed) 63 64 if errorOccurred { 65 return errors.New("copy finished with errors, please review the logs") 66 } 67 return err 68 } 69 70 func getCopyParams(f *spec.File) (copyParams services.MoveCopyParams, err error) { 71 copyParams = services.NewMoveCopyParams() 72 copyParams.CommonParams, err = f.ToCommonParams() 73 if err != nil { 74 return 75 } 76 copyParams.Recursive, err = f.IsRecursive(true) 77 if err != nil { 78 return 79 } 80 copyParams.ExcludeArtifacts, err = f.IsExcludeArtifacts(false) 81 if err != nil { 82 return 83 } 84 copyParams.IncludeDeps, err = f.IsIncludeDeps(false) 85 if err != nil { 86 return 87 } 88 copyParams.Flat, err = f.IsFlat(false) 89 if err != nil { 90 return 91 } 92 return 93 }