Skip to content

Commit

Permalink
Race condition in RunCmdWithOutputParser
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi committed Nov 29, 2023
1 parent 7461a0e commit 58d6ffb
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 75 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ require (
golang.org/x/sys v0.12.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/jfrog/gofrog => github.com/eranturgeman/gofrog v0.0.0-20231129122220-0328729640c2
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jfrog/gofrog v1.3.1 h1:QqAwQXCVReT724uga1AYqG/ZyrNQ6f+iTxmzkb+YFQk=
github.com/jfrog/gofrog v1.3.1/go.mod h1:IFMc+V/yf7rA5WZ74CSbXe+Lgf0iApEQLxRZVzKRUR0=
github.com/eranturgeman/gofrog v0.0.0-20231129122220-0328729640c2 h1:DNuz2sqfF4B/Acrv0ve0ZdAWRIqdOQOziPvk1Uxpt4M=
github.com/eranturgeman/gofrog v0.0.0-20231129122220-0328729640c2/go.mod h1:AQo5Fq0G9nDEF6icH7MYQK0iohR4HuEAXl8jaxRuT6Q=
github.com/klauspost/cpuid/v2 v2.2.3 h1:sxCkb+qR91z4vsqw4vGGZlDgPz3G7gjaLyK3V8y70BU=
github.com/klauspost/cpuid/v2 v2.2.3/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
Expand Down
65 changes: 0 additions & 65 deletions utils/command.go

This file was deleted.

9 changes: 5 additions & 4 deletions utils/goutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"regexp"
"runtime"

"github.com/jfrog/gofrog/io"
"github.com/jfrog/gofrog/version"

"os"
Expand Down Expand Up @@ -39,7 +40,7 @@ func RunGo(goArg []string, repoUrl string) error {
return err
}

goCmd := NewCommand("go", "", goArg)
goCmd := io.NewCommand("go", "", goArg)
err = prepareGlobalRegExp()
if err != nil {
return err
Expand Down Expand Up @@ -148,7 +149,7 @@ func runDependenciesCmd(projectDir string, commandArgs []string, log Log) (outpu
}
}()
}
goCmd := NewCommand("go", "", commandArgs)
goCmd := io.NewCommand("go", "", commandArgs)
goCmd.Dir = projectDir

err = prepareGlobalRegExp()
Expand Down Expand Up @@ -230,7 +231,7 @@ func GetParsedGoVersion() (*version.Version, error) {
}

func getGoVersion() (string, error) {
goCmd := NewCommand("go", "version", nil)
goCmd := io.NewCommand("go", "version", nil)
output, err := gofrogcmd.RunCmdOutput(goCmd)
return output, err
}
Expand Down Expand Up @@ -288,7 +289,7 @@ func GetGoModCachePath() (string, error) {

// GetGOPATH returns the location of the GOPATH
func getGOPATH() (string, error) {
goCmd := NewCommand("go", "env", []string{"GOPATH"})
goCmd := io.NewCommand("go", "env", []string{"GOPATH"})
output, err := gofrogcmd.RunCmdOutput(goCmd)
if err != nil {
return "", fmt.Errorf("could not find GOPATH env: %s", err.Error())
Expand Down
5 changes: 3 additions & 2 deletions utils/pythonutils/pipenvutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package pythonutils

import (
"encoding/json"
"github.com/jfrog/build-info-go/utils"

"github.com/jfrog/gofrog/io"
)

// Executes pipenv graph.
Expand All @@ -11,7 +12,7 @@ import (
// 'topLevelPackagesList' - list of all top level dependencies ( root dependencies only)
func getPipenvDependencies(srcPath string) (dependenciesGraph map[string][]string, topLevelDependencies []string, err error) {
// Run pipenv graph
pipenvGraphCmd := utils.NewCommand("pipenv", "graph", []string{"--json"})
pipenvGraphCmd := io.NewCommand("pipenv", "graph", []string{"--json"})
pipenvGraphCmd.Dir = srcPath
output, err := pipenvGraphCmd.RunWithOutput()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion utils/pythonutils/piputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/jfrog/build-info-go/utils"
"github.com/jfrog/gofrog/io"
)

// Executes the pip-dependency-map script and returns a dependency map of all the installed pip packages in the current environment to and another list of the top level dependencies
Expand All @@ -18,7 +19,7 @@ func getPipDependencies(srcPath, dependenciesDirName string) (map[string][]strin
if err != nil {
return nil, nil, err
}
localPipdeptree := utils.NewCommand("python", "", []string{localPipdeptreeScript, "--json"})
localPipdeptree := io.NewCommand("python", "", []string{localPipdeptreeScript, "--json"})
localPipdeptree.Dir = srcPath
output, err := localPipdeptree.RunWithOutput()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion utils/pythonutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/jfrog/build-info-go/entities"
"github.com/jfrog/build-info-go/utils"
"github.com/jfrog/gofrog/io"
gofrogcmd "github.com/jfrog/gofrog/io"
)

Expand Down Expand Up @@ -210,7 +211,7 @@ func InstallWithLogParsing(tool PythonTool, commandArgs []string, log utils.Log,
// Add verbosity flag to pipenv commands to collect necessary data
commandArgs = append(commandArgs, "-v")
}
installCmd := utils.NewCommand(string(tool), "install", commandArgs)
installCmd := io.NewCommand(string(tool), "install", commandArgs)
installCmd.Dir = srcPath

dependenciesMap := map[string]entities.Dependency{}
Expand Down

0 comments on commit 58d6ffb

Please sign in to comment.