safe file checking (#946)

This commit is contained in:
Zachary Rice authored and GitHub committed 2022-08-08 14:16:50 -05:00
1 parent 6f6e057042
commit b828cacde5
1 file changed
+16 -2
+16 -2
View File
@@ -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"))
}
@@ -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
}