1
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

View File

@ -1,7 +1,7 @@
package utils
import (
"io/ioutil"
"os"
"strconv"
"strings"
@ -29,13 +29,17 @@ func ConvertFileSize(size int64) (float64, string, string) {
}
func DirectorySize(path string) (dirSz int64, err error) {
dir, err := ioutil.ReadDir(path)
dir, err := os.ReadDir(path)
if err != nil {
return 0, errors.Wrapf(err, "failed to compute %s directory size", path)
}
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