diff --git a/commands/audit/scarunner.go b/commands/audit/scarunner.go index c26ea0d4..f7fd98c3 100644 --- a/commands/audit/scarunner.go +++ b/commands/audit/scarunner.go @@ -177,18 +177,18 @@ func getDirectDependenciesFromTree(dependencyTrees []*xrayCmdUtils.GraphNode) [] func getCurationCacheByTech(tech coreutils.Technology) (string, error) { if tech == coreutils.Maven { - return xrayutils.GetCurationMavenCacheFolder(true) + return xrayutils.GetCurationMavenCacheFolder() } return "", nil } func GetTechDependencyTree(params xrayutils.AuditParams, tech coreutils.Technology) (flatTree *xrayCmdUtils.GraphNode, fullDependencyTrees []*xrayCmdUtils.GraphNode, err error) { logMessage := fmt.Sprintf("Calculating %s dependencies", tech.ToFormal()) - // in case it's not curation command these params will be empty curationLogMsg, curationCacheFolder, err := getCurationCacheFolderAndLogMsg(params, tech) if err != nil { return } + // In case it's not curation command these 'curationLogMsg' be empty logMessage += curationLogMsg log.Info(logMessage + "...") if params.Progress() != nil { @@ -248,25 +248,26 @@ func GetTechDependencyTree(params xrayutils.AuditParams, tech coreutils.Technolo } func getCurationCacheFolderAndLogMsg(params xrayutils.AuditParams, tech coreutils.Technology) (logMessage string, curationCacheFolder string, err error) { - if params.IsCurationCmd() { - curationCacheFolder, err = getCurationCacheByTech(tech) - if err != nil { - return logMessage, curationCacheFolder, err - } + if !params.IsCurationCmd() { + return + } + if curationCacheFolder, err = getCurationCacheByTech(tech); err != nil { + return + } - if isExist, err := fileutils.IsDirExists(curationCacheFolder, false); isExist { - if isEmpty, err := fileutils.IsDirEmpty(curationCacheFolder); !isEmpty { - return logMessage, curationCacheFolder, err - } else if err != nil { - return logMessage, curationCacheFolder, err - } - } else if err != nil { - return logMessage, curationCacheFolder, err + dirExist, err := fileutils.IsDirExists(curationCacheFolder, false) + if err != nil { + return + } + + if dirExist { + if dirIsEmpty, err := fileutils.IsDirEmpty(curationCacheFolder); err != nil || !dirIsEmpty { + return } + } - logMessage = ". Project's cache is currently empty, so this run may take longer to complete" + logMessage = ". Project's cache is currently empty, so this run may take longer to complete" - } return logMessage, curationCacheFolder, err } diff --git a/commands/curation/curationaudit_test.go b/commands/curation/curationaudit_test.go index 0fcb2f54..cdaedfc0 100644 --- a/commands/curation/curationaudit_test.go +++ b/commands/curation/curationaudit_test.go @@ -500,7 +500,7 @@ func getTestCasesForDoCurationAudit() []testCase { assert.NoError(t, err) // set the cache to test project dir, in order to fill its cache with dependencies callbackPreTest := clienttestutils.ChangeDirWithCallback(t, rootDir, filepath.Join("..", "test")) - curationCache, err := utils.GetCurationMavenCacheFolder(true) + curationCache, err := utils.GetCurationMavenCacheFolder() callbackPreTest() require.NoError(t, err) return []string{"com.jfrog:maven-dep-tree:tree", "-DdepsTreeOutputFile=output", "-Dmaven.repo.local=" + curationCache} diff --git a/utils/paths.go b/utils/paths.go index 79fd24ac..7293185e 100644 --- a/utils/paths.go +++ b/utils/paths.go @@ -38,24 +38,21 @@ func GetCurationCacheFolder() (string, error) { return filepath.Join(curationFolder, "cache"), nil } -func GetCurationMavenCacheFolder(withProjectDir bool) (string, error) { +func GetCurationMavenCacheFolder() (projectDir string, err error) { curationFolder, err := GetCurationCacheFolder() if err != nil { return "", err } - projectDir := "" - if withProjectDir { - workingDir, err := os.Getwd() - if err != nil { - return "", err - } - // #nosec G401 -- Not a secret hash. - hasher := sha1.New() - _, err = hasher.Write([]byte(workingDir)) - if err != nil { - return "", err - } - projectDir = hex.EncodeToString(hasher.Sum(nil)) + workingDir, err := os.Getwd() + if err != nil { + return "", err + } + // #nosec G401 -- Not a secret hash. + hasher := sha1.New() + _, err = hasher.Write([]byte(workingDir)) + if err != nil { + return "", err } - return filepath.Join(curationFolder, "maven", projectDir), nil + projectDir = filepath.Join(curationFolder, "maven", hex.EncodeToString(hasher.Sum(nil))) + return }