Wrap an error message. Return 0 size on error.
This commit is contained in:
parent
04dedc5f5c
commit
f7390b0763
@ -6,6 +6,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var sizeSuffixes = [...]string{"B", "KiB", "MiB", "GiB", "TiB"}
|
var sizeSuffixes = [...]string{"B", "KiB", "MiB", "GiB", "TiB"}
|
||||||
@ -30,7 +32,7 @@ func ConvertFileSize(size int64) (float64, string, string) {
|
|||||||
func DirectorySize(path string) (dirSz int64, err error) {
|
func DirectorySize(path string) (dirSz int64, err error) {
|
||||||
err = filepath.Walk(path, func(_ string, info fs.FileInfo, err error) error {
|
err = filepath.Walk(path, func(_ string, info fs.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrapf(err, "failed to compute %s directory size", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
dirSz += info.Size()
|
dirSz += info.Size()
|
||||||
@ -39,7 +41,7 @@ func DirectorySize(path string) (dirSz int64, err error) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return dirSz, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return dirSz, nil
|
return dirSz, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user