From be37f743172d31b6bf307eee9dfa0053650dcb06 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 7 Feb 2022 22:18:22 +0400 Subject: [PATCH] Storage size computing moved off to utils.DirectorySize(). --- internal/handlers/handlers.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index b0084b4..b873b51 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -11,11 +11,9 @@ import ( "fmt" "html/template" "io" - "io/fs" "net/http" "os" "path" - "path/filepath" "time" "github.com/eknkc/amber" @@ -65,15 +63,10 @@ func (h *UploadHandlers) Index(w http.ResponseWriter, r *http.Request) { var fMaxSize int64 = h.conf.Uploads.Limits.FileSize << 20 var storSize int64 = 0 - filepath.Walk(h.conf.Uploads.Directory, func(_ string, info fs.FileInfo, err error) error { - if err != nil { - return err - } - - storSize += info.Size() - - return nil - }) + storSize, err := utils.DirectorySize(h.conf.Uploads.Directory) + if err != nil { + h.logErr.Printf("cannot compute storage size: %s", err) + } _, _, capStr := utils.ConvertFileSize(storCapacity) _, _, usedStr := utils.ConvertFileSize(storSize)