Avoid race condition while calculating directory size of server
This commit is contained in:
parent
ac9ab4c0b0
commit
d3cbf96c57
|
@ -18,6 +18,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -170,10 +171,11 @@ func (fs *Filesystem) DirectorySize(dir string) (int64, error) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
s, _ := fs.DirectorySize(p)
|
s, _ := fs.DirectorySize(p)
|
||||||
size += s
|
|
||||||
|
atomic.AddInt64(&size, s)
|
||||||
}(filepath.Join(cleaned, f.Name()))
|
}(filepath.Join(cleaned, f.Name()))
|
||||||
} else {
|
} else {
|
||||||
size += f.Size()
|
atomic.AddInt64(&size, f.Size())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user