Skip to content

Commit

Permalink
👻 debug
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <[email protected]>
  • Loading branch information
pranavgaikwad committed Jan 15, 2025
1 parent 6a0829d commit c49a252
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions provider/internal/builtin/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func runOSSpecificGrepCommand(pattern string, location string, providerContext p
var err error
var utilName string

excludePatterns := getGloblikeExcludePatterns(providerContext, log)
excludePatterns := getGloblikeExcludePatterns(providerContext)

if runtime.GOOS == "windows" {
utilName = "powershell.exe"
Expand Down Expand Up @@ -634,8 +634,9 @@ func runOSSpecificGrepCommand(pattern string, location string, providerContext p
$excluded_paths = $env.EXCLUDEDPATHS -split ','
`
}
findstr := exec.Command(utilName, "-Command",
fmt.Sprintf(psScript, exclusionEnvVar, exclusionScript))
psScript = fmt.Sprintf(psScript, exclusionEnvVar, exclusionScript)
findstr := exec.Command(utilName, "-Command", psScript)
log.Info("running ps script with excluded patterns", "patterns", fmt.Sprintf("%v", excludePatterns))
findstr.Env = append(os.Environ(),
"PATTERN="+pattern,
"FILEPATHS="+strings.Join(locations, ","),
Expand Down Expand Up @@ -696,6 +697,7 @@ func runOSSpecificGrepCommand(pattern string, location string, providerContext p
findArgs = append(findArgs, "{}", "+")
find.Args = append(find.Args, findPaths...)
find.Args = append(find.Args, findArgs...)
log.V(5).Info("running find with args", "args", find.Args)
outputBytes, err = find.Output()
}
if err != nil {
Expand All @@ -718,7 +720,7 @@ func isSlashEscaped(str string) bool {
}

// golang patterns don't work the same as glob patterns on shell
func getGloblikeExcludePatterns(ctx provider.ProviderContext, log logr.Logger) []string {
func getGloblikeExcludePatterns(ctx provider.ProviderContext) []string {
patterns := []string{}
for _, pattern := range ctx.GetExcludePatterns() {
pattern = strings.ReplaceAll(pattern, ".*", "*")
Expand All @@ -727,9 +729,6 @@ func getGloblikeExcludePatterns(ctx provider.ProviderContext, log logr.Logger) [
pattern = re.ReplaceAllString(pattern, "[!$1]")
pattern = strings.TrimPrefix(pattern, "^")
pattern = strings.TrimSuffix(pattern, "$")
if strings.Contains(pattern, "\\") || strings.Contains(pattern, "{") {
log.V(5).Info("unsupported regex pattern for exclusion", pattern)
}
if pattern == "" {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion provider/internal/builtin/service_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func Test_builtinServiceClient_Evaluate_InclusionExclusion(t *testing.T) {
config: provider.InitConfig{
Location: baseLocation,
},
log: testr.New(t),
log: testr.NewWithOptions(t, testr.Options{Verbosity: 20}),
includedPaths: tt.includedPathsFromConfig,
locationCache: map[string]float64{},
cacheMutex: sync.RWMutex{},
Expand Down

0 comments on commit c49a252

Please sign in to comment.