1
0
Fork 0

In DirectorySize() filepath.Walk was replaced by ioutil.ReadDir to shorten the code.

This commit is contained in:
Alexander Andreev 2023-05-26 17:22:21 +04:00
parent da001dbe39
commit 54f87951c1
Signed by: Arav
GPG Key ID: D22A817D95815393
1 changed files with 7 additions and 11 deletions

View File

@ -29,19 +29,15 @@ func ConvertFileSize(size int64) (float64, string, string) {
}
func DirectorySize(path string) (dirSz int64, err error) {
err = filepath.Walk(path, func(_ string, info fs.FileInfo, err error) error {
if err != nil {
return errors.Wrapf(err, "failed to compute %s directory size", path)
}
dirSz += info.Size()
return nil
})
dir, err := ioutil.ReadDir(path)
if err != nil {
return 0, err
return 0, errors.Wrapf(err, "failed to compute %s directory size", path)
}
for _, entry := range dir {
dirSz += entry.Size()
}
// Here we subtract a size of a directory's inode to get size of files only.
return dirSz - 4096, nil
}