diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f5f70781c..d9eacf141 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -90,7 +90,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - ref: ${{ github.event.pull_request.head.sha }} + ref: ${{ github.event.pull_request.head.sha }} - name: Setup Go with cache uses: jfrog/.github/actions/install-go-with-cache@main diff --git a/README.md b/README.md index dc62bf74b..f1722d8f9 100644 --- a/README.md +++ b/README.md @@ -470,9 +470,13 @@ params.TargetProps = targetProps TargetPathInArchive := "archive/path/" // Size limit for files to be uploaded. SizeLimit= &fspatterns.SizeThreshold{SizeInBytes: 10000, Condition: fspatterns.LessThan} + +uploadServiceOptions := &UploadServiceOptions{ // Set to true to fail the upload operation if any of the files fail to upload -failFast := false -totalUploaded, totalFailed, err := rtManager.UploadFiles(failFast, params) +FailFast: false, +} + +totalUploaded, totalFailed, err := rtManager.UploadFiles(uploadServiceOptions, params) ``` #### Downloading Files from Artifactory @@ -549,10 +553,12 @@ calling `Close()` on the OperationSummary struct. params := services.NewUploadParams() params.Pattern = "repo/*/*.zip" params.Target = "repo/path/" -// Set to true to fail the upload operation if any of the files fail to upload -failFast := false +uploadServiceOptions := &UploadServiceOptions{ + // Set to true to fail the upload operation if any of the files fail to upload + FailFast: false, +} -summary, err := rtManager.UploadFilesWithSummary(failFast, params) +summary, err := rtManager.UploadFilesWithSummary(uploadServiceOptions, params) defer summary.Close() reader, totalDownloaded, totalExpected, err := rtManager.DownloadFilesWithResultReader(params) diff --git a/artifactory/emptymanager.go b/artifactory/emptymanager.go index eac95735d..a7149ca1e 100644 --- a/artifactory/emptymanager.go +++ b/artifactory/emptymanager.go @@ -56,8 +56,8 @@ type ArtifactoryServicesManager interface { SetProps(params services.PropsParams) (int, error) DeleteProps(params services.PropsParams) (int, error) GetItemProps(relativePath string) (*utils.ItemProperties, error) - UploadFiles(failFast bool, params ...services.UploadParams) (totalUploaded, totalFailed int, err error) - UploadFilesWithSummary(failFast bool, params ...services.UploadParams) (operationSummary *utils.OperationSummary, err error) + UploadFiles(uploadServiceOptions UploadServiceOptions, params ...services.UploadParams) (totalUploaded, totalFailed int, err error) + UploadFilesWithSummary(uploadServiceOptions UploadServiceOptions, params ...services.UploadParams) (operationSummary *utils.OperationSummary, err error) Copy(params ...services.MoveCopyParams) (successCount, failedCount int, err error) Move(params ...services.MoveCopyParams) (successCount, failedCount int, err error) PublishGoProject(params _go.GoParams) (*utils.OperationSummary, error) @@ -262,11 +262,11 @@ func (esm *EmptyArtifactoryServicesManager) GetItemProps(string) (*utils.ItemPro panic("Failed: Method is not implemented") } -func (esm *EmptyArtifactoryServicesManager) UploadFiles(_ bool, _ ...services.UploadParams) (int, int, error) { +func (esm *EmptyArtifactoryServicesManager) UploadFiles(_ UploadServiceOptions, _ ...services.UploadParams) (int, int, error) { panic("Failed: Method is not implemented") } -func (esm *EmptyArtifactoryServicesManager) UploadFilesWithSummary(_ bool, _ ...services.UploadParams) (*utils.OperationSummary, error) { +func (esm *EmptyArtifactoryServicesManager) UploadFilesWithSummary(_ UploadServiceOptions, _ ...services.UploadParams) (*utils.OperationSummary, error) { panic("Failed: Method is not implemented") } diff --git a/artifactory/manager.go b/artifactory/manager.go index ff48a5bf4..f79409e8f 100644 --- a/artifactory/manager.go +++ b/artifactory/manager.go @@ -302,20 +302,25 @@ func (sm *ArtifactoryServicesManagerImp) GetItemProps(relativePath string) (*uti return setPropsService.GetItemProperties(relativePath) } -func (sm *ArtifactoryServicesManagerImp) initUploadService() *services.UploadService { +type UploadServiceOptions struct { + // Fail the operation immediately if an error occurs. + failFast bool +} + +func (sm *ArtifactoryServicesManagerImp) initUploadService(uploadServiceOptions UploadServiceOptions) *services.UploadService { uploadService := services.NewUploadService(sm.client) uploadService.Threads = sm.config.GetThreads() uploadService.ArtDetails = sm.config.GetServiceDetails() uploadService.DryRun = sm.config.IsDryRun() + uploadService.SetFailFast(uploadServiceOptions.failFast) uploadService.Progress = sm.progress httpClientDetails := uploadService.ArtDetails.CreateHttpClientDetails() uploadService.MultipartUpload = utils.NewMultipartUpload(sm.client, &httpClientDetails, uploadService.ArtDetails.GetUrl()) return uploadService } -func (sm *ArtifactoryServicesManagerImp) UploadFiles(failFast bool, params ...services.UploadParams) (totalUploaded, totalFailed int, err error) { - uploadService := sm.initUploadService() - uploadService.SetFailFast(failFast) +func (sm *ArtifactoryServicesManagerImp) UploadFiles(uploadServiceOptions UploadServiceOptions, params ...services.UploadParams) (totalUploaded, totalFailed int, err error) { + uploadService := sm.initUploadService(uploadServiceOptions) summary, err := uploadService.UploadFiles(params...) if summary == nil { return 0, 0, err @@ -323,10 +328,9 @@ func (sm *ArtifactoryServicesManagerImp) UploadFiles(failFast bool, params ...se return summary.TotalSucceeded, summary.TotalFailed, err } -func (sm *ArtifactoryServicesManagerImp) UploadFilesWithSummary(failFast bool, params ...services.UploadParams) (operationSummary *utils.OperationSummary, err error) { - uploadService := sm.initUploadService() +func (sm *ArtifactoryServicesManagerImp) UploadFilesWithSummary(uploadServiceOptions UploadServiceOptions, params ...services.UploadParams) (operationSummary *utils.OperationSummary, err error) { + uploadService := sm.initUploadService(uploadServiceOptions) uploadService.SetSaveSummary(true) - uploadService.SetFailFast(failFast) return uploadService.UploadFiles(params...) }