diff --git a/cmd/dwelling-upload-clean/main.go b/cmd/dwelling-upload-clean/main.go index 04f1e23..8c9751a 100644 --- a/cmd/dwelling-upload-clean/main.go +++ b/cmd/dwelling-upload-clean/main.go @@ -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 diff --git a/pkg/utils/filesize.go b/pkg/utils/filesize.go index 8b74ead..1100a5b 100644 --- a/pkg/utils/filesize.go +++ b/pkg/utils/filesize.go @@ -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()) }