diff options
author | Eng Zer Jun <engzerjun@gmail.com> | 2023-05-11 23:35:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-11 15:35:52 +0000 |
commit | 089320aadc9beb2c09db8c6cc66e10b312256614 (patch) | |
tree | 67c7aaf5ef89fb41ca066167ec27fa6e206e15ba | |
parent | b2fb2ef276e38405e358c6be8a32d41de609ee00 (diff) |
lib: replace `Readdir(-1)` with `os.ReadDir` (#8901)
-rw-r--r-- | lib/api/api.go | 8 | ||||
-rw-r--r-- | lib/db/backend/leveldb_open.go | 15 |
2 files changed, 8 insertions, 15 deletions
diff --git a/lib/api/api.go b/lib/api/api.go index 5e41badb6a..38b5d2c929 100644 --- a/lib/api/api.go +++ b/lib/api/api.go @@ -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 } diff --git a/lib/db/backend/leveldb_open.go b/lib/db/backend/leveldb_open.go index 1f5f14acdb..32a5585df2 100644 --- a/lib/db/backend/leveldb_open.go +++ b/lib/db/backend/leveldb_open.go @@ -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() } |