From cefb8af7a1aec112f0f1f35f123db08aa3149968 Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Sat, 10 Apr 2021 21:27:43 +0200 Subject: [PATCH] Hide free space if it can't be calculated Signed-off-by: Richard Steinmetz --- lib/SystemStatistics.php | 19 ++++++++++++++++++- templates/settings-admin.php | 5 +++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php index f3ce0721..1dd2865f 100644 --- a/lib/SystemStatistics.php +++ b/lib/SystemStatistics.php @@ -24,6 +24,7 @@ use OC\Files\View; use OC\Installer; +use OCP\Files\FileInfo; use OCP\IConfig; use OCP\App\IAppManager; use bantu\IniGetWrapper\IniGetWrapper; @@ -77,7 +78,7 @@ public function getSystemStatistics() { 'filelocking.enabled' => $this->config->getSystemValue('filelocking.enabled', true) ? 'yes' : 'no', 'memcache.locking' => $this->config->getSystemValue('memcache.locking', 'none'), 'debug' => $this->config->getSystemValue('debug', false) ? 'yes' : 'no', - 'freespace' => $this->view->free_space(), + 'freespace' => $this->getFreeSpace(), 'cpuload' => $processorUsage['loadavg'], 'mem_total' => $memoryUsage['mem_total'], 'mem_free' => $memoryUsage['mem_free'], @@ -222,4 +223,20 @@ protected function getProcessorUsage() { 'loadavg' => $loadavg ]; } + + /** + * Get free space if it can be calculated. + * + * @return mixed free space or null + * @throws \OCP\Files\InvalidPathException + */ + protected function getFreeSpace() { + $free_space = $this->view->free_space(); + if ($free_space === FileInfo::SPACE_UNKNOWN + || $free_space === FileInfo::SPACE_UNLIMITED + || $free_space === FileInfo::SPACE_NOT_COMPUTED) { + return null; + } + return $free_space; + } } diff --git a/templates/settings-admin.php b/templates/settings-admin.php index 6806a80e..1fef1ba9 100644 --- a/templates/settings-admin.php +++ b/templates/settings-admin.php @@ -151,8 +151,9 @@ function FormatMegabytes($byte) {

t('Files:')); ?>

t('Storages:')); ?>

-

t('Free Space:')); ?> -

+ +

t('Free Space:')); ?>

+