fix(common): simplify size check

This commit is contained in:
shirou 2022-07-19 12:43:41 +00:00
parent 5610fbc5d5
commit 839e8b731f
1 changed files with 2 additions and 10 deletions

View File

@ -313,19 +313,11 @@ func PathExists(filename string) bool {
// PathExistsWithContents returns the filename exists and it is not empty // PathExistsWithContents returns the filename exists and it is not empty
func PathExistsWithContents(filename string) bool { func PathExistsWithContents(filename string) bool {
if _, err := os.Stat(filename); err != nil { info, err := os.Stat(filename)
return false
}
f, err := os.Open(filename)
if err != nil { if err != nil {
return false return false
} }
defer f.Close() return info.Size() > 4 // at least 4 bytes
r := bufio.NewReader(f)
_, err = r.Peek(4) // check first 4 bytes
return err == nil
} }
// GetEnv retrieves the environment variable key. If it does not exist it returns the default. // GetEnv retrieves the environment variable key. If it does not exist it returns the default.