Merge pull request #39 from pterodactyl/fix/2154

Calculate disk usage even if server has 'unlimited' disk space
This commit is contained in:
Dane Everitt 2020-07-12 12:02:27 -07:00 committed by GitHub
commit 6fd7ed23e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
// 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 {
var space = fs.Server.Build.DiskSpace
// If space is -1 or 0 just return true, means they're allowed unlimited.
if space <= 0 {
return true
}
space := fs.Server.Build.DiskSpace
// 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.
if x, exists := fs.Server.Cache.Get("disk_used"); exists {
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
}
@ -194,6 +196,15 @@ func (fs *Filesystem) HasSpaceAvailable() bool {
// been allocated.
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
}