Skip to content

Commit

Permalink
fix: correct handling of ./ scan target prefix
Browse files Browse the repository at this point in the history
When the scan target is specified with a `./` prefix, we currently
incorrectly build relative file paths within the project directory.

Also ensure that we correctly handle the cases where a trailing
slash is either present or absent, on a directory path specified
as scan target.
  • Loading branch information
spdawson committed Nov 1, 2022
1 parent 610e056 commit 0ff1477
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/commands/process/balancer/filelist/filelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package filelist

import (
"io/fs"
"os"
"path/filepath"
"strings"

Expand All @@ -16,6 +17,18 @@ import (
func Discover(projectPath string, config settings.Config) ([]work.File, error) {
var files []work.File

fileStat, statErr := os.Stat(projectPath)
if statErr != nil {
log.Debug().Msgf("Failed to stat project path %s : %s", projectPath, statErr)
return files, statErr
}

if fileStat.IsDir() {
projectPath = strings.TrimPrefix(projectPath, "./")
projectPath = strings.TrimSuffix(projectPath, "/")
projectPath += "/"
}

ignore := fileignore.New(projectPath, config)

err := filepath.WalkDir(projectPath, func(filePath string, d fs.DirEntry, err error) error {
Expand Down

0 comments on commit 0ff1477

Please sign in to comment.