Calculate disk usage even if server has 'unlimited' disk space
This commit is contained in:
parent
eefc11bd0d
commit
a98e376593
|
@ -162,17 +162,19 @@ func (fs *Filesystem) ParallelSafePath(paths []string) ([]string, error) {
|
||||||
// Because determining the amount of space being used by a server is a taxing operation we
|
// Because determining the amount of space being used by a server is a taxing operation we
|
||||||
// will load it all up into a cache and pull from that as long as the key is not expired.
|
// will load it all up into a cache and pull from that as long as the key is not expired.
|
||||||
func (fs *Filesystem) HasSpaceAvailable() bool {
|
func (fs *Filesystem) HasSpaceAvailable() bool {
|
||||||
var space = fs.Server.Build.DiskSpace
|
space := fs.Server.Build.DiskSpace
|
||||||
|
|
||||||
// If space is -1 or 0 just return true, means they're allowed unlimited.
|
|
||||||
if space <= 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we have a match in the cache, use that value in the return. No need to perform an expensive
|
// If we have a match in the cache, use that value in the return. No need to perform an expensive
|
||||||
// disk operation, even if this is an empty value.
|
// disk operation, even if this is an empty value.
|
||||||
if x, exists := fs.Server.Cache.Get("disk_used"); exists {
|
if x, exists := fs.Server.Cache.Get("disk_used"); exists {
|
||||||
fs.Server.Resources.Disk = x.(int64)
|
fs.Server.Resources.Disk = x.(int64)
|
||||||
|
|
||||||
|
// This check is here to ensure that true is always returned if the server has unlimited disk space.
|
||||||
|
// See the end of this method for more information (the other `if space <= 0`).
|
||||||
|
if space <= 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
return (x.(int64) / 1000.0 / 1000.0) <= space
|
return (x.(int64) / 1000.0 / 1000.0) <= space
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +196,15 @@ func (fs *Filesystem) HasSpaceAvailable() bool {
|
||||||
// been allocated.
|
// been allocated.
|
||||||
fs.Server.Resources.Disk = size
|
fs.Server.Resources.Disk = size
|
||||||
|
|
||||||
|
// If space is -1 or 0 just return true, means they're allowed unlimited.
|
||||||
|
//
|
||||||
|
// Technically we could skip disk space calculation because we don't need to check if the server exceeds it's limit
|
||||||
|
// but because this method caches the disk usage it would be best to calculate the disk usage and always
|
||||||
|
// return true.
|
||||||
|
if space <= 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
return (size / 1000.0 / 1000.0) <= space
|
return (size / 1000.0 / 1000.0) <= space
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user