Skip to content

Commit

Permalink
Add failFast flag to UploadFiles(), UploadFilesWithSummary() (#1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
omerzi authored Sep 16, 2024
1 parent 71e6988 commit 81a0c90
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,9 @@ params.TargetProps = targetProps
TargetPathInArchive := "archive/path/"
// Size limit for files to be uploaded.
SizeLimit= &fspatterns.SizeThreshold{SizeInBytes: 10000, Condition: fspatterns.LessThan}
totalUploaded, totalFailed, err := rtManager.UploadFiles(params)
// 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)
```

#### Downloading Files from Artifactory
Expand Down Expand Up @@ -547,8 +549,10 @@ 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

summary, err := rtManager.UploadFilesWithSummary(params)
summary, err := rtManager.UploadFilesWithSummary(failFast, params)
defer summary.Close()
reader, totalDownloaded, totalExpected, err := rtManager.DownloadFilesWithResultReader(params)

Expand Down
13 changes: 4 additions & 9 deletions artifactory/emptymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ type ArtifactoryServicesManager interface {
SetProps(params services.PropsParams) (int, error)
DeleteProps(params services.PropsParams) (int, error)
GetItemProps(relativePath string) (*utils.ItemProperties, error)
UploadFilesWithSummary(params ...services.UploadParams) (operationSummary *utils.OperationSummary, err error)
UploadFiles(params ...services.UploadParams) (totalUploaded, totalFailed int, err error)
UploadFilesWithFailFast(params ...services.UploadParams) (totalUploaded, totalFailed int, err error)
UploadFiles(failFast bool, params ...services.UploadParams) (totalUploaded, totalFailed int, err error)
UploadFilesWithSummary(failFast bool, 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)
Expand Down Expand Up @@ -263,15 +262,11 @@ func (esm *EmptyArtifactoryServicesManager) GetItemProps(string) (*utils.ItemPro
panic("Failed: Method is not implemented")
}

func (esm *EmptyArtifactoryServicesManager) UploadFiles(...services.UploadParams) (int, int, error) {
func (esm *EmptyArtifactoryServicesManager) UploadFiles(_ bool, _ ...services.UploadParams) (int, int, error) {
panic("Failed: Method is not implemented")
}

func (esm *EmptyArtifactoryServicesManager) UploadFilesWithFailFast(...services.UploadParams) (int, int, error) {
panic("Failed: Method is not implemented")
}

func (esm *EmptyArtifactoryServicesManager) UploadFilesWithSummary(...services.UploadParams) (*utils.OperationSummary, error) {
func (esm *EmptyArtifactoryServicesManager) UploadFilesWithSummary(_ bool, _ ...services.UploadParams) (*utils.OperationSummary, error) {
panic("Failed: Method is not implemented")
}

Expand Down
17 changes: 5 additions & 12 deletions artifactory/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,27 +313,20 @@ func (sm *ArtifactoryServicesManagerImp) initUploadService() *services.UploadSer
return uploadService
}

func (sm *ArtifactoryServicesManagerImp) UploadFiles(params ...services.UploadParams) (totalUploaded, totalFailed int, err error) {
return sm.uploadFiles(sm.initUploadService(), params...)
}

func (sm *ArtifactoryServicesManagerImp) UploadFilesWithFailFast(params ...services.UploadParams) (totalUploaded, totalFailed int, err error) {
func (sm *ArtifactoryServicesManagerImp) UploadFiles(failFast bool, params ...services.UploadParams) (totalUploaded, totalFailed int, err error) {
uploadService := sm.initUploadService()
uploadService.SetFailFast(true)
return sm.uploadFiles(uploadService, params...)
}

func (sm *ArtifactoryServicesManagerImp) uploadFiles(uploadService *services.UploadService, uploadParams ...services.UploadParams) (totalUploaded, totalFailed int, err error) {
summary, err := uploadService.UploadFiles(uploadParams...)
uploadService.SetFailFast(failFast)
summary, err := uploadService.UploadFiles(params...)
if summary == nil {
return 0, 0, err
}
return summary.TotalSucceeded, summary.TotalFailed, err
}

func (sm *ArtifactoryServicesManagerImp) UploadFilesWithSummary(params ...services.UploadParams) (operationSummary *utils.OperationSummary, err error) {
func (sm *ArtifactoryServicesManagerImp) UploadFilesWithSummary(failFast bool, params ...services.UploadParams) (operationSummary *utils.OperationSummary, err error) {
uploadService := sm.initUploadService()
uploadService.SetSaveSummary(true)
uploadService.SetFailFast(failFast)
return uploadService.UploadFiles(params...)
}

Expand Down

0 comments on commit 81a0c90

Please sign in to comment.