In DirectorySize() filepath.Walk was replaced by ioutil.ReadDir to shorten the code.
This commit is contained in:
parent
da001dbe39
commit
54f87951c1
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user