Skip to content

Commit

Permalink
simplified and explained new logic
Browse files Browse the repository at this point in the history
  • Loading branch information
eranturgeman committed Sep 15, 2024
1 parent 17dc5be commit 101d7b6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions utils/techutils/techutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,17 @@ func getExistingRootDir(path string, workingDirectoryToIndicators map[string][]s
return
}

// This functions checks if wd is a PATH prefix for root. Examples:
// root = dir1/dir2/dir3 | wd = dir1/dir --> false (wd is prefix to root, but is not actually a valid part of its path)
// root = dir1/dir2/dir3 | wd = dir1/dir2 --> true
func hasCompletePathPrefix(root, wd string) bool {
if strings.HasPrefix(root, wd) {
amountOfSkippedChars := len(wd)
partialRoot := root[amountOfSkippedChars:]
if partialRoot == "" || partialRoot[0] == filepath.Separator {
return true
}
if !strings.HasPrefix(root, wd) {
return false
}
return false
rootParts := strings.Split(root, string(filepath.Separator))
wdParts := strings.Split(wd, string(filepath.Separator))
idxToCheck := len(wdParts) - 1
return rootParts[idxToCheck] == wdParts[idxToCheck]
}

// DetectedTechnologiesToSlice returns a string slice that includes all the names of the detected technologies.
Expand Down

0 comments on commit 101d7b6

Please sign in to comment.