lib: replace Readdir(-1) with os.ReadDir (#8901)

This commit is contained in:
Eng Zer Jun 2023-05-11 23:35:52 +08:00 committed by GitHub
parent b2fb2ef276
commit 089320aadc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 15 deletions

View File

@ -1865,13 +1865,7 @@ func (v jsonVersionVector) MarshalJSON() ([]byte, error) {
}
func dirNames(dir string) []string {
fd, err := os.Open(dir)
if err != nil {
return nil
}
defer fd.Close()
fis, err := fd.Readdir(-1)
fis, err := os.ReadDir(dir)
if err != nil {
return nil
}

View File

@ -200,22 +200,21 @@ func dbIsLarge(location string) bool {
return false
}
dir, err := os.Open(location)
if err != nil {
return false
}
fis, err := dir.Readdir(-1)
entries, err := os.ReadDir(location)
if err != nil {
return false
}
var size int64
for _, fi := range fis {
if fi.Name() == "LOG" {
for _, entry := range entries {
if entry.Name() == "LOG" {
// don't count the size
continue
}
fi, err := entry.Info()
if err != nil {
continue
}
size += fi.Size()
}