Skip to content

Commit

Permalink
Merge branch 'dev' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi authored Nov 13, 2024
2 parents 6ffcfe1 + f0d689e commit 75d7271
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 107 deletions.
54 changes: 23 additions & 31 deletions artifactory/services/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ func CollectFilesForUpload(uploadParams UploadParams, progressMgr ioutils.Progre
buildProps += vcsProps
}
uploadData := UploadData{Artifact: artifact, TargetProps: props, BuildProps: buildProps}
incGeneralProgressTotal(progressMgr, uploadParams)
if progressMgr != nil {
progressMgr.IncGeneralProgressTotalBy(1)
}
dataHandlerFunc(uploadData)
return nil
}
Expand Down Expand Up @@ -355,9 +357,10 @@ func scanFilesByPattern(uploadParams UploadParams, rootPath string, progressMgr
continue
}
uploadedDirs = append(uploadedDirs, path)
} else if progressMgr != nil {
// Increment the progress counter for each file (no increment for directories is needed)
progressMgr.IncGeneralProgressTotalBy(1)
}
// Update progress
incGeneralProgressTotal(progressMgr, uploadParams)
// Create upload task
err = createUploadTask(taskData, dataHandlerFunc, uploadParams.Regexp)
if err != nil {
Expand Down Expand Up @@ -391,16 +394,6 @@ func skipDirUpload(targetFiles, sourceDirs []string, targetDir, sourceDir string
return false
}

func incGeneralProgressTotal(progressMgr ioutils.ProgressMgr, uploadParams UploadParams) {
if progressMgr != nil {
if uploadParams.Archive != "" {
progressMgr.IncGeneralProgressTotalBy(2)
} else {
progressMgr.IncGeneralProgressTotalBy(1)
}
}
}

type uploadTaskData struct {
target string
path string
Expand Down Expand Up @@ -479,24 +472,24 @@ func getUploadTarget(rootPath, target string, isFlat, placeholdersUsed bool) str

// Uploads the file in the specified local path to the specified target path.
// Returns true if the file was successfully uploaded.
func (us *UploadService) uploadFile(artifact UploadData, uploadParams UploadParams, logMsgPrefix string) (*fileutils.FileDetails, bool, error) {
func (us *UploadService) uploadFile(uploadData UploadData, uploadParams UploadParams, logMsgPrefix string) (*fileutils.FileDetails, bool, error) {
var checksumDeployed = false
var resp *http.Response
var details *fileutils.FileDetails
var body []byte
targetPathWithProps, err := buildUploadUrls(us.ArtDetails.GetUrl(), artifact.Artifact.TargetPath, artifact.BuildProps, uploadParams.GetDebian(), artifact.TargetProps)
targetPathWithProps, err := buildUploadUrls(us.ArtDetails.GetUrl(), uploadData.Artifact.TargetPath, uploadData.BuildProps, uploadParams.GetDebian(), uploadData.TargetProps)
if err != nil {
return nil, false, err
}
fileInfo, err := os.Lstat(artifact.Artifact.LocalPath)
fileInfo, err := os.Lstat(uploadData.Artifact.LocalPath)
if errorutils.CheckError(err) != nil {
return nil, false, err
}
httpClientsDetails := us.ArtDetails.CreateHttpClientDetails()
if uploadParams.IsSymlink() && fileutils.IsFileSymlink(fileInfo) {
resp, details, body, err = us.uploadSymlink(targetPathWithProps, logMsgPrefix, httpClientsDetails, uploadParams)
} else {
resp, details, body, checksumDeployed, err = us.doUpload(artifact, targetPathWithProps, logMsgPrefix, httpClientsDetails, fileInfo, uploadParams)
resp, details, body, checksumDeployed, err = us.doUpload(uploadData.Artifact, targetPathWithProps, logMsgPrefix, httpClientsDetails, uploadParams)
}
if err != nil {
return nil, false, err
Expand Down Expand Up @@ -595,10 +588,10 @@ func (us *UploadService) uploadSymlink(targetPath, logMsgPrefix string, httpClie
return
}

func (us *UploadService) doUpload(artifact UploadData, targetUrlWithProps, logMsgPrefix string, httpClientsDetails httputils.HttpClientDetails, fileInfo os.FileInfo, uploadParams UploadParams) (
func (us *UploadService) doUpload(artifact clientutils.Artifact, targetUrlWithProps, logMsgPrefix string, httpClientsDetails httputils.HttpClientDetails, uploadParams UploadParams) (
resp *http.Response, details *fileutils.FileDetails, body []byte, checksumDeployed bool, err error) {
// Get local file details
details, err = fileutils.GetFileDetails(artifact.Artifact.LocalPath, uploadParams.ChecksumsCalcEnabled)
details, err = fileutils.GetFileDetails(artifact.LocalPath, uploadParams.ChecksumsCalcEnabled)
if err != nil {
return
}
Expand All @@ -609,7 +602,7 @@ func (us *UploadService) doUpload(artifact UploadData, targetUrlWithProps, logMs
}

// Try checksum deploy
if us.shouldTryChecksumDeploy(fileInfo.Size(), uploadParams) {
if us.shouldTryChecksumDeploy(details.Size, uploadParams) {
resp, body, err = us.doChecksumDeploy(details, targetUrlWithProps, httpClientsDetails, us.client)
if err != nil {
return resp, details, body, checksumDeployed, err
Expand All @@ -625,13 +618,13 @@ func (us *UploadService) doUpload(artifact UploadData, targetUrlWithProps, logMs

// Try multipart upload
var shouldTryMultipart bool
if shouldTryMultipart, err = us.shouldDoMultipartUpload(fileInfo.Size(), uploadParams); err != nil {
if shouldTryMultipart, err = us.shouldDoMultipartUpload(details.Size, uploadParams); err != nil {
return
}
if shouldTryMultipart {
var checksumToken string
if checksumToken, err = us.MultipartUpload.UploadFileConcurrently(artifact.Artifact.LocalPath, artifact.Artifact.TargetPath,
fileInfo.Size(), details.Checksum.Sha1, us.Progress, uploadParams.SplitCount, uploadParams.ChunkSize); err != nil {
if checksumToken, err = us.MultipartUpload.UploadFileConcurrently(artifact.LocalPath, artifact.TargetPath,
details.Size, details.Checksum.Sha1, us.Progress, uploadParams.SplitCount, uploadParams.ChunkSize); err != nil {
return
}
// Once the file is uploaded to the storage, we finalize the multipart upload by performing a checksum deployment to save the file in Artifactory.
Expand All @@ -642,7 +635,7 @@ func (us *UploadService) doUpload(artifact UploadData, targetUrlWithProps, logMs

// Do regular upload
addExplodeHeader(&httpClientsDetails, uploadParams.IsExplodeArchive())
resp, body, err = utils.UploadFile(artifact.Artifact.LocalPath, targetUrlWithProps, logMsgPrefix, &us.ArtDetails, details,
resp, body, err = utils.UploadFile(artifact.LocalPath, targetUrlWithProps, logMsgPrefix, &us.ArtDetails, details,
httpClientsDetails, us.client, uploadParams.ChecksumsCalcEnabled, us.Progress)
return
}
Expand Down Expand Up @@ -792,9 +785,6 @@ func (us *UploadService) createArtifactHandlerFunc(uploadResult *utils.Result, u
if err != nil {
return
}
if us.Progress != nil {
us.Progress.IncrementGeneralProgress()
}
uploaded = true
} else {
// Upload file
Expand Down Expand Up @@ -1017,12 +1007,14 @@ func buildUploadUrls(artifactoryUrl, targetPath, buildProps, debianConfig string
return
}

func addPropsToTargetPath(targetPath, buildProps, debConfig string, props *utils.Properties) (string, error) {
func addPropsToTargetPath(targetPath, buildProps, debConfig string, targetProps *utils.Properties) (string, error) {
pathParts := []string{targetPath}

encodedTargetProps := props.ToEncodedString(false)
if len(encodedTargetProps) > 0 {
pathParts = append(pathParts, encodedTargetProps)
if targetProps != nil {
encodedTargetProps := targetProps.ToEncodedString(false)
if len(encodedTargetProps) > 0 {
pathParts = append(pathParts, encodedTargetProps)
}
}

debianProps, err := utils.ParseProperties(getDebianProps(debConfig))
Expand Down
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
module github.com/jfrog/jfrog-client-go

go 1.22.7
go 1.22.9

require (
github.com/ProtonMail/go-crypto v1.0.0
github.com/ProtonMail/go-crypto v1.1.2
github.com/buger/jsonparser v1.1.1
github.com/forPelevin/gomoji v1.2.0
github.com/go-git/go-git/v5 v5.12.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang-jwt/jwt/v4 v4.5.1
github.com/gookit/color v1.5.4
github.com/jfrog/archiver/v3 v3.6.1
github.com/jfrog/build-info-go v1.10.4
github.com/jfrog/build-info-go v1.10.5
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-20240909161429-701f63a606c0
golang.org/x/term v0.24.0
golang.org/x/crypto v0.29.0
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
golang.org/x/term v0.26.0
)

require (
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.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.25.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/tools v0.27.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
Loading

0 comments on commit 75d7271

Please sign in to comment.