From d3cbf96c57378129e3730897702cf781c8947e27 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 10 Apr 2020 16:14:04 -0700 Subject: [PATCH] Avoid race condition while calculating directory size of server --- server/filesystem.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/filesystem.go b/server/filesystem.go index 02b6e2b..e597269 100644 --- a/server/filesystem.go +++ b/server/filesystem.go @@ -18,6 +18,7 @@ import ( "strconv" "strings" "sync" + "sync/atomic" "time" ) @@ -170,10 +171,11 @@ func (fs *Filesystem) DirectorySize(dir string) (int64, error) { defer wg.Done() s, _ := fs.DirectorySize(p) - size += s + + atomic.AddInt64(&size, s) }(filepath.Join(cleaned, f.Name())) } else { - size += f.Size() + atomic.AddInt64(&size, f.Size()) } }