Skip to content

Commit

Permalink
fix(common): simplify size check
Browse files Browse the repository at this point in the history
  • Loading branch information
shirou committed Jul 19, 2022
1 parent 5610fbc commit 839e8b7
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions internal/common/common.go
Expand Up @@ -313,19 +313,11 @@ func PathExists(filename string) bool {

// PathExistsWithContents returns the filename exists and it is not empty
func PathExistsWithContents(filename string) bool {
if _, err := os.Stat(filename); err != nil {
return false
}

f, err := os.Open(filename)
info, err := os.Stat(filename)
if err != nil {
return false
}
defer f.Close()

r := bufio.NewReader(f)
_, err = r.Peek(4) // check first 4 bytes
return err == nil
return info.Size() > 4 // at least 4 bytes
}

// GetEnv retrieves the environment variable key. If it does not exist it returns the default.
Expand Down

0 comments on commit 839e8b7

Please sign in to comment.