1
0
Fork 0

Replaced deprecated ioutil.ReadDir() with os.ReadDir() + os.Stat() in filesize.go.

This commit is contained in:
Alexander Andreev 2023-08-05 05:03:34 +04:00
parent b513a5ff1d
commit df8baf153b
Signed by: Arav
GPG Key ID: D22A817D95815393
1 changed files with 7 additions and 3 deletions

View File

@ -1,7 +1,7 @@
package utils package utils
import ( import (
"io/ioutil" "os"
"strconv" "strconv"
"strings" "strings"
@ -29,13 +29,17 @@ func ConvertFileSize(size int64) (float64, string, string) {
} }
func DirectorySize(path string) (dirSz int64, err error) { func DirectorySize(path string) (dirSz int64, err error) {
dir, err := ioutil.ReadDir(path) dir, err := os.ReadDir(path)
if err != nil { if err != nil {
return 0, errors.Wrapf(err, "failed to compute %s directory size", path) return 0, errors.Wrapf(err, "failed to compute %s directory size", path)
} }
for _, entry := range dir { for _, entry := range dir {
dirSz += entry.Size() file, err := os.Stat(entry.Name())
if err != nil {
return 0, errors.Wrapf(err, "failed to stat a file %s", entry.Name())
}
dirSz += file.Size()
} }
return dirSz, nil return dirSz, nil