Skip to content

Commit

Permalink
Remove pointer from embedded checksum struct (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
Or-Geva authored Jan 13, 2022
1 parent 035b888 commit 9210476
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 46 deletions.
9 changes: 6 additions & 3 deletions artifactory/services/download.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package services

import (
biutils "github.com/jfrog/build-info-go/utils"
"github.com/jfrog/gofrog/version"
"net/http"
"os"
"path"
"path/filepath"
"sort"

biutils "github.com/jfrog/build-info-go/utils"
"github.com/jfrog/gofrog/version"

"github.com/jfrog/build-info-go/entities"

"github.com/jfrog/jfrog-client-go/http/httpclient"

"github.com/jfrog/gofrog/parallel"
Expand Down Expand Up @@ -344,7 +347,7 @@ func createDependencyTransferDetails(downloadPath, localPath, localFileName stri
func createDependencyArtifactDetails(resultItem utils.ResultItem) utils.ArtifactDetails {
fileInfo := utils.ArtifactDetails{
ArtifactoryPath: resultItem.GetItemRelativePath(),
Checksums: utils.Checksums{
Checksums: entities.Checksum{
Sha1: resultItem.Actual_Sha1,
Md5: resultItem.Actual_Md5,
},
Expand Down
12 changes: 7 additions & 5 deletions artifactory/services/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package services
import (
"archive/zip"
"fmt"
biutils "github.com/jfrog/build-info-go/utils"
"io"
"net/http"
"os"
Expand All @@ -13,6 +12,9 @@ import (
"strconv"
"strings"

"github.com/jfrog/build-info-go/entities"
biutils "github.com/jfrog/build-info-go/utils"

"github.com/jfrog/gofrog/parallel"
"github.com/jfrog/jfrog-client-go/artifactory/services/fspatterns"
"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
Expand Down Expand Up @@ -911,7 +913,7 @@ func newResultManager() (*resultsManager, error) {
}

// Write a result of a successful upload
func (rm *resultsManager) addFinalResult(localPath, targetPath, targetUrl, sha256 string, checksums *fileutils.ChecksumDetails) {
func (rm *resultsManager) addFinalResult(localPath, targetPath, targetUrl, sha256 string, checksums *entities.Checksum) {
fileTransferDetails := clientutils.FileTransferDetails{
SourcePath: localPath,
TargetPath: targetUrl,
Expand All @@ -920,7 +922,7 @@ func (rm *resultsManager) addFinalResult(localPath, targetPath, targetUrl, sha25
rm.singleFinalTransfersWriter.Write(fileTransferDetails)
artifactDetails := utils.ArtifactDetails{
ArtifactoryPath: targetPath,
Checksums: utils.Checksums{
Checksums: entities.Checksum{
Sha256: checksums.Sha256,
Sha1: checksums.Sha1,
Md5: checksums.Md5,
Expand All @@ -947,7 +949,7 @@ func (rm *resultsManager) addNotFinalResult(localPath, targetUrl string) error {
}

// Mark all the transfers to a specific target as completed successfully
func (rm *resultsManager) finalizeResult(targetPath string, checksums *fileutils.ChecksumDetails) error {
func (rm *resultsManager) finalizeResult(targetPath string, checksums *entities.Checksum) error {
writer := rm.notFinalTransfersWriters[targetPath]
e := writer.Close()
if e != nil {
Expand All @@ -957,7 +959,7 @@ func (rm *resultsManager) finalizeResult(targetPath string, checksums *fileutils
delete(rm.notFinalTransfersWriters, targetPath)
artifactDetails := utils.ArtifactDetails{
ArtifactoryPath: targetPath,
Checksums: utils.Checksums{
Checksums: entities.Checksum{
Sha256: checksums.Sha256,
Sha1: checksums.Sha1,
Md5: checksums.Md5,
Expand Down
17 changes: 6 additions & 11 deletions artifactory/services/utils/resultutils.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package utils

import (
"strings"

buildinfo "github.com/jfrog/build-info-go/entities"
"github.com/jfrog/jfrog-client-go/utils/io/content"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"strings"
)

type Result struct {
Expand Down Expand Up @@ -36,8 +37,8 @@ type OperationSummary struct {

type ArtifactDetails struct {
// Path of the artifact in Artifactory
ArtifactoryPath string `json:"artifactoryPath,omitempty"`
Checksums Checksums `json:"checksums,omitempty"`
ArtifactoryPath string `json:"artifactoryPath,omitempty"`
Checksums buildinfo.Checksum `json:"checksums,omitempty"`
}

func (cs *OperationSummary) Close() error {
Expand All @@ -49,7 +50,7 @@ func (cs *OperationSummary) Close() error {
}

func (ad *ArtifactDetails) ToBuildInfoArtifact() buildinfo.Artifact {
artifact := buildinfo.Artifact{Checksum: &buildinfo.Checksum{}}
artifact := buildinfo.Artifact{Checksum: buildinfo.Checksum{}}
artifact.Sha1 = ad.Checksums.Sha1
artifact.Md5 = ad.Checksums.Md5
// Artifact name in build info as the name in artifactory
Expand All @@ -63,7 +64,7 @@ func (ad *ArtifactDetails) ToBuildInfoArtifact() buildinfo.Artifact {
}

func (ad *ArtifactDetails) ToBuildInfoDependency() buildinfo.Dependency {
dependency := buildinfo.Dependency{Checksum: &buildinfo.Checksum{}}
dependency := buildinfo.Dependency{Checksum: buildinfo.Checksum{}}
dependency.Sha1 = ad.Checksums.Sha1
dependency.Md5 = ad.Checksums.Md5
// Artifact name in build info as the name in artifactory
Expand All @@ -87,9 +88,3 @@ func ConvertArtifactsDetailsToBuildInfoDependencies(artifactsDetailsReader *cont
}
return buildDependencies, artifactsDetailsReader.GetError()
}

type Checksums struct {
Sha256 string `json:"sha256,omitempty"`
Sha1 string `json:"sha1,omitempty"`
Md5 string `json:"md5,omitempty"`
}
4 changes: 2 additions & 2 deletions artifactory/services/utils/searchutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,11 @@ func addSeparator(str1, separator, str2 string) string {
}

func (item *ResultItem) ToArtifact() buildinfo.Artifact {
return buildinfo.Artifact{Name: item.Name, Checksum: &buildinfo.Checksum{Sha1: item.Actual_Sha1, Md5: item.Actual_Md5}, Path: path.Join(item.Path, item.Name)}
return buildinfo.Artifact{Name: item.Name, Checksum: buildinfo.Checksum{Sha1: item.Actual_Sha1, Md5: item.Actual_Md5}, Path: path.Join(item.Path, item.Name)}
}

func (item *ResultItem) ToDependency() buildinfo.Dependency {
return buildinfo.Dependency{Id: item.Name, Checksum: &buildinfo.Checksum{Sha1: item.Actual_Sha1, Md5: item.Actual_Md5}}
return buildinfo.Dependency{Id: item.Name, Checksum: buildinfo.Checksum{Sha1: item.Actual_Sha1, Md5: item.Actual_Md5}}
}

type AqlSearchResultItemFilter func(SearchBasedContentItem, *content.ContentReader) (*content.ContentReader, error)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ exclude (
golang.org/x/text v0.3.4
)

//replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v0.1.5-0.20211209071650-c5f4d2e581c3
replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.0.1-0.20220112142814-65cb52a6452a

//replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.0.7-0.20211128152632-e218c460d703
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/jfrog/build-info-go v1.0.0 h1:4JsL8zfHDZqVpMwKICPY7qqyrqsFZzT0XzobI1Eu840=
github.com/jfrog/build-info-go v1.0.0/go.mod h1:QyeMfNGt4W0eWazrd7j6uZVN5KTpB05nxF/MwvGnTqs=
github.com/jfrog/build-info-go v1.0.1-0.20220112142814-65cb52a6452a h1:nrAWFSt+6JokebYeohWvZ6A/rbcy1IY5JOhwHkH/G6E=
github.com/jfrog/build-info-go v1.0.1-0.20220112142814-65cb52a6452a/go.mod h1:QyeMfNGt4W0eWazrd7j6uZVN5KTpB05nxF/MwvGnTqs=
github.com/jfrog/gofrog v1.1.1 h1:uRjeZWidQl4FmKP4Zpj5hSKJp3gSIWW9VUwbQdVEVRU=
github.com/jfrog/gofrog v1.1.1/go.mod h1:9YN5v4LlsCfLIXpwQnzSf1wVtgjdHM20FzuIu58RMI4=
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 h1:DowS9hvgyYSX4TO5NpyC606/Z4SxnNYbT+WX27or6Ck=
Expand Down
2 changes: 1 addition & 1 deletion tests/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ func createDummyBuild(buildName string) error {
{
Type: "gz",
Name: "c.tar.gz",
Checksum: &buildinfo.Checksum{
Checksum: buildinfo.Checksum{
Sha1: "9d4336ff7bc2d2348aee4e27ad55e42110df4a80",
Md5: "b4918187cc9b3bf1b0772546d9398d7d",
},
Expand Down
24 changes: 10 additions & 14 deletions utils/io/fileutils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"encoding/json"
"errors"
biutils "github.com/jfrog/build-info-go/utils"
"io"
"io/ioutil"
"net/url"
Expand All @@ -15,6 +14,9 @@ import (
"reflect"
"strings"

"github.com/jfrog/build-info-go/entities"
biutils "github.com/jfrog/build-info-go/utils"

"github.com/jfrog/jfrog-client-go/utils/errorutils"
)

Expand Down Expand Up @@ -350,7 +352,7 @@ func GetFileDetails(filePath string, includeChecksums bool) (*FileDetails, error
return details, err
}
} else {
details.Checksum = ChecksumDetails{}
details.Checksum = entities.Checksum{}
}

file, err := os.Open(filePath)
Expand All @@ -366,11 +368,11 @@ func GetFileDetails(filePath string, includeChecksums bool) (*FileDetails, error
return details, nil
}

func calcChecksumDetails(filePath string) (ChecksumDetails, error) {
func calcChecksumDetails(filePath string) (entities.Checksum, error) {
file, err := os.Open(filePath)
defer file.Close()
if errorutils.CheckError(err) != nil {
return ChecksumDetails{}, err
return entities.Checksum{}, err
}
return calcChecksumDetailsFromReader(file)
}
Expand All @@ -393,25 +395,19 @@ func GetFileDetailsFromReader(reader io.Reader, includeChecksusms bool) (*FileDe
return details, err
}

func calcChecksumDetailsFromReader(reader io.Reader) (ChecksumDetails, error) {
func calcChecksumDetailsFromReader(reader io.Reader) (entities.Checksum, error) {
checksumInfo, err := biutils.CalcChecksums(reader)
if err != nil {
return ChecksumDetails{}, errorutils.CheckError(err)
return entities.Checksum{}, errorutils.CheckError(err)
}
return ChecksumDetails{Md5: checksumInfo[biutils.MD5], Sha1: checksumInfo[biutils.SHA1], Sha256: checksumInfo[biutils.SHA256]}, nil
return entities.Checksum{Md5: checksumInfo[biutils.MD5], Sha1: checksumInfo[biutils.SHA1], Sha256: checksumInfo[biutils.SHA256]}, nil
}

type FileDetails struct {
Checksum ChecksumDetails
Checksum entities.Checksum
Size int64
}

type ChecksumDetails struct {
Md5 string
Sha1 string
Sha256 string
}

func CopyFile(dst, src string) error {
srcFile, err := os.Open(src)
if err != nil {
Expand Down
9 changes: 2 additions & 7 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strconv"
"strings"

"github.com/jfrog/build-info-go/entities"
"github.com/jfrog/gofrog/stringutils"

"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
Expand Down Expand Up @@ -507,13 +508,7 @@ func (details *DeployableArtifactDetails) CreateFileTransferDetails(rtUrl, targe
}

type UploadResponseBody struct {
Checksums ChecksumDetails `json:"checksums,omitempty"`
}

type ChecksumDetails struct {
Md5 string
Sha1 string
Sha256 string
Checksums entities.Checksum `json:"checksums,omitempty"`
}

func SaveFileTransferDetailsInTempFile(filesDetails *[]FileTransferDetails) (string, error) {
Expand Down

0 comments on commit 9210476

Please sign in to comment.