Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failFast flag to UploadFiles(), UploadFilesWithSummary() #1021

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading