Avoid race condition while calculating directory size of server

This commit is contained in:
Dane Everitt 2020-04-10 16:14:04 -07:00
parent ac9ab4c0b0
commit d3cbf96c57
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -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())
}
}