Skip to content

Commit

Permalink
copy dir
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Sverdlov <[email protected]>
  • Loading branch information
sverdlov93 committed Aug 31, 2023
1 parent 817c5f8 commit f8dd980
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 82 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/jfrog/jfrog-client-go
go 1.20

require (
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371
github.com/buger/jsonparser v1.1.1
github.com/forPelevin/gomoji v1.1.8
github.com/go-git/go-git/v5 v5.8.1
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/gookit/color v1.5.4
github.com/jfrog/build-info-go v1.9.8
github.com/jfrog/build-info-go v1.9.9
github.com/jfrog/gofrog v1.3.0
github.com/mholt/archiver/v3 v3.5.1
github.com/stretchr/testify v1.8.4
Expand All @@ -21,7 +21,7 @@ require (

require (
dario.cat/mergo v1.0.0 // indirect
github.com/CycloneDX/cyclonedx-go v0.7.1 // indirect
github.com/CycloneDX/cyclonedx-go v0.7.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/andybalholm/brotli v1.0.1 // indirect
Expand Down Expand Up @@ -57,6 +57,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230803131422-8230595ceb86
replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230831090828-915afc4d7380

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog dev
16 changes: 10 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/CycloneDX/cyclonedx-go v0.7.1 h1:5w1SxjGm9MTMNTuRbEPyw21ObdbaagTWF/KfF0qHTRE=
github.com/CycloneDX/cyclonedx-go v0.7.1/go.mod h1:N/nrdWQI2SIjaACyyDs/u7+ddCkyl/zkNs8xFsHF2Ps=
github.com/CycloneDX/cyclonedx-go v0.7.2 h1:kKQ0t1dPOlugSIYVOMiMtFqeXI2wp/f5DBIdfux8gnQ=
github.com/CycloneDX/cyclonedx-go v0.7.2/go.mod h1:K2bA+324+Og0X84fA8HhN2X066K7Bxz4rpMQ4ZhjtSk=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs=
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc=
Expand Down Expand Up @@ -51,8 +51,8 @@ github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
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/jfrog/build-info-go v1.9.8 h1:D8/ga+YgQpqp/CJj2zteS4/twmSy8zvm1v9lCd2Kv1M=
github.com/jfrog/build-info-go v1.9.8/go.mod h1:t31QRpH5xUJKw8XkQlAA+Aq7aanyS1rrzpcK8xSNVts=
github.com/jfrog/build-info-go v1.8.9-0.20230831090828-915afc4d7380 h1:zfcXR/kIDe5npI+k0FdY0pWVTOLbK5kNkf0W0C7r6Gk=
github.com/jfrog/build-info-go v1.8.9-0.20230831090828-915afc4d7380/go.mod h1:QEskae5fQpjeY2PBzsjWtUQVskYSNDF2sSmw/Gx44dQ=
github.com/jfrog/gofrog v1.3.0 h1:o4zgsBZE4QyDbz2M7D4K6fXPTBJht+8lE87mS9bw7Gk=
github.com/jfrog/gofrog v1.3.0/go.mod h1:IFMc+V/yf7rA5WZ74CSbXe+Lgf0iApEQLxRZVzKRUR0=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
Expand Down Expand Up @@ -102,11 +102,15 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/terminalstatic/go-xsd-validate v0.1.5 h1:RqpJnf6HGE2CB/lZB1A8BYguk8uRtcvYAPLCF15qguo=
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ulikunitz/xz v0.5.9 h1:RsKRIA2MO8x56wkkcd3LbtcE/uMszhb6DpRf+3uwa3I=
github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
Expand Down
File renamed without changes.
File renamed without changes.
68 changes: 1 addition & 67 deletions utils/io/fileutils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
biutils "github.com/jfrog/build-info-go/utils"
gofrog "github.com/jfrog/gofrog/io"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"golang.org/x/exp/slices"
)

const (
Expand Down Expand Up @@ -417,71 +416,6 @@ type FileDetails struct {
Size int64
}

func CopyFile(dst, src string) (err error) {
srcFile, err := os.Open(src)
if err != nil {
return errorutils.CheckError(err)
}
defer func() {
err = errors.Join(err, errorutils.CheckError(srcFile.Close()))
}()
fileName, _ := GetFileAndDirFromPath(src)
dstPath, err := CreateFilePath(dst, fileName)
if err != nil {
return err
}
dstFile, err := os.Create(dstPath)
if err != nil {
return errorutils.CheckError(err)
}
defer func() {
err = errors.Join(err, errorutils.CheckError(dstFile.Close()))
}()
_, err = io.Copy(dstFile, srcFile)
return errorutils.CheckError(err)
}

// Copy directory content from one path to another.
// includeDirs means to copy also the dirs if presented in the src folder.
// excludeNames - Skip files/dirs in the src folder that match names in provided slice. ONLY excludes first layer (only in src folder).
func CopyDir(fromPath, toPath string, includeDirs bool, excludeNames []string) error {
err := CreateDirIfNotExist(toPath)
if err != nil {
return err
}

files, err := ListFiles(fromPath, includeDirs)
if err != nil {
return err
}

for _, v := range files {
// Skip if excluded
if slices.Contains(excludeNames, filepath.Base(v)) {
continue
}

dir, err := IsDirExists(v, false)
if err != nil {
return err
}

if dir {
toPath := toPath + GetFileSeparator() + filepath.Base(v)
err := CopyDir(v, toPath, true, nil)
if err != nil {
return err
}
continue
}
err = CopyFile(toPath, v)
if err != nil {
return err
}
}
return err
}

// Removing the provided path from the filesystem
func RemovePath(testPath string) error {
if _, err := os.Stat(testPath); err == nil {
Expand All @@ -496,7 +430,7 @@ func RemovePath(testPath string) error {

// Renaming from old path to new path.
func RenamePath(oldPath, newPath string) error {
err := CopyDir(oldPath, newPath, true, nil)
err := biutils.CopyDir(oldPath, newPath, true, nil)
if err != nil {
return errors.New("Error copying directory: " + oldPath + "to" + newPath + err.Error())
}
Expand Down
3 changes: 2 additions & 1 deletion utils/io/fileutils/files_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fileutils

import (
biutils "github.com/jfrog/build-info-go/utils"
"github.com/jfrog/jfrog-client-go/utils/io"
"os"
"path/filepath"
Expand Down Expand Up @@ -262,7 +263,7 @@ func TestRemoveDirContents(t *testing.T) {
defer func() {
assert.NoError(t, RemoveTempDir(tmpDirPath))
}()
err = CopyDir(filepath.Join("testdata", "removedircontents"), tmpDirPath, true, nil)
err = biutils.CopyDir(filepath.Join("testdata", "removedircontents"), tmpDirPath, true, nil)
assert.NoError(t, err)

// Run the function
Expand Down
7 changes: 4 additions & 3 deletions utils/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tests
import (
"bufio"
"errors"
biutils "github.com/jfrog/build-info-go/utils"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/jfrog/jfrog-client-go/utils/log"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -107,13 +108,13 @@ func exitOnErr(err error) {

func InitVcsSubmoduleTestDir(t *testing.T, srcPath, tmpDir string) (submodulePath string) {
var err error
assert.NoError(t, fileutils.CopyDir(srcPath, tmpDir, true, nil))
assert.NoError(t, biutils.CopyDir(srcPath, tmpDir, true, nil))
if found, err := fileutils.IsDirExists(filepath.Join(tmpDir, "gitdata"), false); found {
assert.NoError(t, err)
assert.NoError(t, fileutils.RenamePath(filepath.Join(tmpDir, "gitdata"), filepath.Join(tmpDir, ".git")))
}
submoduleDst := filepath.Join(tmpDir, "subdir", "submodule")
assert.NoError(t, fileutils.CopyFile(submoduleDst, filepath.Join(tmpDir, "gitSubmoduleData")))
assert.NoError(t, biutils.CopyFile(submoduleDst, filepath.Join(tmpDir, "gitSubmoduleData")))
assert.NoError(t, fileutils.MoveFile(filepath.Join(submoduleDst, "gitSubmoduleData"), filepath.Join(submoduleDst, ".git")))
submodulePath, err = filepath.Abs(submoduleDst)
assert.NoError(t, err)
Expand All @@ -122,7 +123,7 @@ func InitVcsSubmoduleTestDir(t *testing.T, srcPath, tmpDir string) (submodulePat

func InitVcsWorktreeTestDir(t *testing.T, srcPath, tmpDir string) (worktreePath string) {
var err error
assert.NoError(t, fileutils.CopyDir(srcPath, tmpDir, true, nil))
assert.NoError(t, biutils.CopyDir(srcPath, tmpDir, true, nil))
if found, err := fileutils.IsDirExists(filepath.Join(tmpDir, "gitdata"), false); found {
assert.NoError(t, err)
assert.NoError(t, fileutils.RenamePath(filepath.Join(tmpDir, "gitdata"), filepath.Join(tmpDir, "bare.git")))
Expand Down
3 changes: 2 additions & 1 deletion utils/vcsdetails_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
biutils "github.com/jfrog/build-info-go/utils"
testsutils "github.com/jfrog/jfrog-client-go/utils/tests"
"github.com/stretchr/testify/assert"
"path/filepath"
Expand Down Expand Up @@ -42,7 +43,7 @@ func TestVcsDetails(t *testing.T) {

func initVcsTestDir(t *testing.T, srcPath, tmpDir string) (projectPath string) {
var err error
assert.NoError(t, fileutils.CopyDir(srcPath, tmpDir, true, nil))
assert.NoError(t, biutils.CopyDir(srcPath, tmpDir, true, nil))
if found, err := fileutils.IsDirExists(filepath.Join(tmpDir, "gitdata"), false); found {
assert.NoError(t, err)
assert.NoError(t, fileutils.RenamePath(filepath.Join(tmpDir, "gitdata"), filepath.Join(tmpDir, ".git")))
Expand Down

0 comments on commit f8dd980

Please sign in to comment.