Skip to content

Commit

Permalink
safe file checking (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
zricethezav committed Aug 8, 2022
1 parent 6f6e057 commit 6748a89
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions cmd/detect.go
Expand Up @@ -71,8 +71,7 @@ func runDetect(cmd *cobra.Command, args []string) {
log.Fatal().Err(err)
}

// check for a .gitleaksignore file
if info, err := os.Stat(filepath.Join(source, ".gitleaksignore")); !os.IsNotExist(err) && !info.IsDir() {
if fileExists(filepath.Join(source, ".gitleaksignore")) {
detector.AddGitleaksIgnore(filepath.Join(source, ".gitleaksignore"))
}

Expand Down Expand Up @@ -131,3 +130,18 @@ func runDetect(cmd *cobra.Command, args []string) {
os.Exit(exitCode)
}
}

func fileExists(fileName string) bool {
// check for a .gitleaksignore file
info, err := os.Stat(fileName)
if err != nil && !os.IsNotExist(err) {
return false
}

if info != nil && err == nil {
if !info.IsDir() {
return true
}
}
return false
}

0 comments on commit 6748a89

Please sign in to comment.