Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalbe4 committed Sep 19, 2024
2 parents 35b0c86 + 412e1ed commit fafcbe3
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,13 @@ 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)

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(uploadServiceOptions, params)
```

#### Downloading Files from Artifactory
Expand Down Expand Up @@ -547,8 +553,12 @@ calling `Close()` on the OperationSummary struct.
params := services.NewUploadParams()
params.Pattern = "repo/*/*.zip"
params.Target = "repo/path/"
uploadServiceOptions := &UploadServiceOptions{
// 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(uploadServiceOptions, 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(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)
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(_ UploadServiceOptions, _ ...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(_ UploadServiceOptions, _ ...services.UploadParams) (*utils.OperationSummary, error) {
panic("Failed: Method is not implemented")
}

Expand Down
27 changes: 12 additions & 15 deletions artifactory/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,37 +302,34 @@ 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(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) {
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...)
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
}
return summary.TotalSucceeded, summary.TotalFailed, err
}

func (sm *ArtifactoryServicesManagerImp) UploadFilesWithSummary(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)
return uploadService.UploadFiles(params...)
}
Expand Down
2 changes: 1 addition & 1 deletion artifactory/services/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func (ds *DownloadService) createFileHandlerFunc(downloadParams DownloadParams,
}
log.Info(fmt.Sprintf("%sDownloading %q to %q", logMsgPrefix, downloadData.Dependency.GetItemRelativePath(), localFullPath))
if err = ds.downloadFileIfNeeded(downloadPath, localPath, localFileName, logMsgPrefix, downloadData, downloadParams); err != nil {
log.Error(logMsgPrefix, "Received an error: "+err.Error())
log.Error(logMsgPrefix + "Received an error: " + err.Error())
return err
}
successCounters[threadId]++
Expand Down
24 changes: 18 additions & 6 deletions artifactory/services/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,19 +858,22 @@ func (us *UploadService) CreateUploadAsZipFunc(uploadResult *utils.Result, targe
}
// Make sure all go routines in readFilesAsZip calls were done.
var zipReadersWg sync.WaitGroup
checksumZipReader := us.readFilesAsZip(archiveDataReader, "Calculating size / checksums",
// We execute readFilesAsZip twice. The first execution is a dry-run.
// It calculates the size and checksums of the generated zip file, which is necessary before starting the upload task.
// The second execution is part of the zip upload process running in parallel to the archiving of them files to the zip.
checksumZipReader := us.readFilesAsZip(archiveDataReader, true,
archiveData.uploadParams.Flat, archiveData.uploadParams.Symlink, saveFilesPathsFunc, errorsQueue, &zipReadersWg)
details, err := fileutils.GetFileDetailsFromReader(checksumZipReader, archiveData.uploadParams.ChecksumsCalcEnabled)
if err != nil {
return
}
log.Info(logMsgPrefix+"Uploading artifact:", targetPath)

getReaderFunc := func() (io.Reader, error) {
archiveDataReader.Reset()
return us.readFilesAsZip(archiveDataReader, "Archiving", archiveData.uploadParams.Flat,
return us.readFilesAsZip(archiveDataReader, false, archiveData.uploadParams.Flat,
archiveData.uploadParams.Symlink, nil, errorsQueue, &zipReadersWg), nil
}

log.Info(logMsgPrefix+"Uploading artifact:", targetPath)
uploaded, err := us.uploadFileFromReader(getReaderFunc, targetUrlWithProps, archiveData.uploadParams, logMsgPrefix, details)

if uploaded {
Expand All @@ -886,12 +889,17 @@ func (us *UploadService) CreateUploadAsZipFunc(uploadResult *utils.Result, targe

// Reads files and streams them as a ZIP to a Reader.
// archiveDataReader is a ContentReader of UploadData items containing the details of the files to stream.
// zipDryRun - If true, this function is run as part of the dry-run process, to
// saveFilesPathsFunc (optional) is a func that is called for each file that is written into the ZIP, and gets the file's local path as a parameter.
func (us *UploadService) readFilesAsZip(archiveDataReader *content.ContentReader, progressPrefix string, flat, symlink bool,
func (us *UploadService) readFilesAsZip(archiveDataReader *content.ContentReader, zipDryRun, flat, symlink bool,
saveFilesPathsFunc func(sourcePath string) error, errorsQueue *clientutils.ErrorsQueue, zipReadersWg *sync.WaitGroup) io.Reader {
pr, pw := io.Pipe()
zipReadersWg.Add(1)

progressPrefix := "Archiving"
if zipDryRun {
progressPrefix = "Calculating size / checksums"
}
go func() {
defer zipReadersWg.Done()
var e error
Expand All @@ -912,6 +920,10 @@ func (us *UploadService) readFilesAsZip(archiveDataReader *content.ContentReader
if e != nil {
errorsQueue.AddError(e)
}
if !zipDryRun && us.Progress != nil {
// Increment general progress by 1 for each file added to the zip if not in dry-run mode.
us.Progress.IncrementGeneralProgress()
}
}
if saveFilesPathsFunc != nil {
e = saveFilesPathsFunc(uploadData.Artifact.LocalPath)
Expand Down Expand Up @@ -979,7 +991,7 @@ func (us *UploadService) addFileToZip(artifact *clientutils.Artifact, progressPr
err = errors.Join(err, errorutils.CheckError(file.Close()))
}
}()
// Show progress bar only for files larger than 250Kb to avoid polluting the terminal with endless progress bars.
// Show progress bar only for files larger than 500kb to avoid polluting the terminal with endless progress bars.
if us.Progress != nil && info.Size() > minFileSizeForProgressInKb {
progressReader := us.Progress.NewProgressReader(info.Size(), progressPrefix, localPath)
reader = progressReader.ActionWithProgress(file)
Expand Down
2 changes: 1 addition & 1 deletion artifactory/usage/reportusage.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func validateAndGetUsageServerInfo(serviceManager artifactory.ArtifactoryService
err = errors.New("Couldn't get Artifactory version. Error: " + err.Error())
return
}
if e := clientutils.ValidateMinimumVersion(clientutils.Artifactory, artifactoryVersion, minArtifactoryVersion); e != nil {
if err = clientutils.ValidateMinimumVersion(clientutils.Artifactory, artifactoryVersion, minArtifactoryVersion); err != nil {
return
}
url, err = clientutils.BuildUrl(rtDetails.GetUrl(), "api/system/usage", make(map[string]string))
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/jfrog/jfrog-client-go

go 1.22
go 1.22.7

require (
github.com/ProtonMail/go-crypto v1.0.0
Expand All @@ -10,13 +10,13 @@ require (
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/gookit/color v1.5.4
github.com/jfrog/archiver/v3 v3.6.1
github.com/jfrog/build-info-go v1.9.36
github.com/jfrog/build-info-go v1.10.0
github.com/jfrog/gofrog v1.7.6
github.com/minio/sha256-simd v1.0.1
github.com/stretchr/testify v1.9.0
github.com/xanzy/ssh-agent v0.3.3
golang.org/x/crypto v0.27.0
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
golang.org/x/term v0.24.0
)

Expand Down Expand Up @@ -49,11 +49,11 @@ require (
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/tools v0.25.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI=
github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw=
github.com/jfrog/build-info-go v1.9.36 h1:bKoYW3o+U70Zbz2kt5NT84N5JWNxdDXHOf+kVdzK+j4=
github.com/jfrog/build-info-go v1.9.36/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
github.com/jfrog/build-info-go v1.10.0 h1:jSxmN58mH0LaP+v1IQadplwJPRILLgI3xieBTXTCSos=
github.com/jfrog/build-info-go v1.10.0/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
Expand Down Expand Up @@ -133,21 +133,21 @@ golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2Uz
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e h1:I88y4caeGeuDQxgdoFPUq097j7kNfw6uvuiNxUBfcBk=
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -189,8 +189,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
const (
Development = "development"
Agent = "jfrog-client-go"
Version = "1.46.2"
Version = "1.47.0"
)

type MinVersionProduct string
Expand Down

0 comments on commit fafcbe3

Please sign in to comment.