mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
fix error handling in IsNonEmptyDir function
This commit is contained in:
parent
73a2df2b0a
commit
471b18de18
2 changed files with 18 additions and 3 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue