fix error handling in IsNonEmptyDir function

This commit is contained in:
wnqqnw19 2025-12-04 10:12:04 -08:00
parent 73a2df2b0a
commit 471b18de18
2 changed files with 18 additions and 3 deletions

View file

@ -77,13 +77,25 @@ func Bytes2Hex(d []byte) string {
// Hex2Bytes returns the bytes represented by the hexadecimal string str.
func Hex2Bytes(str string) []byte {
h, _ := hex.DecodeString(str)
if !isHex(str) {
return nil
}
h, err := hex.DecodeString(str)
if err != nil {
return nil
}
return h
}
// Hex2BytesFixed returns bytes of a specified fixed length flen.
func Hex2BytesFixed(str string, flen int) []byte {
h, _ := hex.DecodeString(str)
if !isHex(str) {
return make([]byte, flen)
}
h, err := hex.DecodeString(str)
if err != nil {
return make([]byte, flen)
}
if len(h) == flen {
return h
}

View file

@ -44,6 +44,9 @@ func IsNonEmptyDir(dir string) bool {
return false
}
defer f.Close()
names, _ := f.Readdirnames(1)
names, err := f.Readdirnames(1)
if err != nil {
return false
}
return len(names) > 0
}