Skip to content

Commit

Permalink
fix: WithScanPath unexpected results (#65)
Browse files Browse the repository at this point in the history
* fix: issue #64

* fix: removed debug log

Co-authored-by: Britton Hayes <[email protected]>
  • Loading branch information
brittonhayes and brittonhayes authored Mar 4, 2022
1 parent 6b39bd2 commit 2b166cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
21 changes: 5 additions & 16 deletions internal/validate/path.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
package validate

import (
"github.com/rs/zerolog/log"

"github.com/spf13/afero"
"os"
)

// Path checks if a file at the given path exists and returns it if so,
// PathExists checks if a file at the given path exists and returns it if so,
// otherwise returns a default path.
func Path(fs afero.Fs, path string) string {
ok, err := afero.Exists(fs, path)
if err != nil {
log.Fatal().Err(err).Send()
}

if ok {
return path
}

log.Fatal().Msg("no valid path provided")
return "."
func PathExists(path string) bool {
_, err := os.Stat(path)
return err == nil
}
13 changes: 12 additions & 1 deletion pkg/hunter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,18 @@ func WithFS(fs afero.Fs) ConfigOption {

func WithScanPath(path string) ConfigOption {
return func(c *Config) {
c.ScanPath = validate.Path(c.Filesystem, c.ScanPath)
if validate.PathExists(path) {
c.ScanPath = path
return
}

currentDir, err := os.Getwd()
if err != nil {
log.Fatal().Err(err).Msg("failed to get current dir")
}

log.Error().Msgf("scan path %q not found, defaulting to %q", path, currentDir)
c.ScanPath = currentDir
}
}

Expand Down

0 comments on commit 2b166cd

Please sign in to comment.