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.
|
// Hex2Bytes returns the bytes represented by the hexadecimal string str.
|
||||||
func Hex2Bytes(str string) []byte {
|
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
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hex2BytesFixed returns bytes of a specified fixed length flen.
|
// Hex2BytesFixed returns bytes of a specified fixed length flen.
|
||||||
func Hex2BytesFixed(str string, flen int) []byte {
|
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 {
|
if len(h) == flen {
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,9 @@ func IsNonEmptyDir(dir string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
names, _ := f.Readdirnames(1)
|
names, err := f.Readdirnames(1)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return len(names) > 0
|
return len(names) > 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue