Oh, in os.Stat() path.Join() is needed, since DirEntry.Name() contains only name of a file itself, not a full path.
This commit is contained in:
parent
df8baf153b
commit
e7e45259ba
@ -33,7 +33,7 @@ func main() {
|
||||
}
|
||||
|
||||
for _, entry := range uploadsDir {
|
||||
file, err := os.Stat(entry.Name())
|
||||
file, err := os.Stat(path.Join(*uploadDir, entry.Name()))
|
||||
if err != nil {
|
||||
log.Printf("failed to stat a file %s: %s", entry.Name(), err)
|
||||
continue
|
||||
|
@ -2,6 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -28,14 +29,14 @@ func ConvertFileSize(size int64) (float64, string, string) {
|
||||
strings.Join([]string{fSizeStr, sizeSuffixes[idx]}, " ")
|
||||
}
|
||||
|
||||
func DirectorySize(path string) (dirSz int64, err error) {
|
||||
dir, err := os.ReadDir(path)
|
||||
func DirectorySize(dirPath string) (dirSz int64, err error) {
|
||||
dir, err := os.ReadDir(dirPath)
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to compute %s directory size", path)
|
||||
return 0, errors.Wrapf(err, "failed to compute %s directory size", dirPath)
|
||||
}
|
||||
|
||||
for _, entry := range dir {
|
||||
file, err := os.Stat(entry.Name())
|
||||
file, err := os.Stat(path.Join(dirPath, entry.Name()))
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "failed to stat a file %s", entry.Name())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user