Replaced deprecated ioutil.ReadDir() with os.ReadDir() + os.Stat() in filesize.go.
This commit is contained in:
parent
b513a5ff1d
commit
df8baf153b
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user