diff options
author | jld3103 <jld3103yt@gmail.com> | 2023-02-15 19:27:04 +0100 |
---|---|---|
committer | jld3103 <jld3103yt@gmail.com> | 2023-07-31 10:29:08 +0200 |
commit | 38db3873a263974645ece09ed5677324f603f08c (patch) | |
tree | e5398eec62ec51bce4091abe1836d9b44ccd1477 /lib/private/legacy/OC_Helper.php | |
parent | 4c10dc2794e0dec16cf3913990d7e154dfde9ee5 (diff) | |
download | nextcloud-server-38db3873a263974645ece09ed5677324f603f08c.tar.gz nextcloud-server-38db3873a263974645ece09ed5677324f603f08c.zip |
provisioning_api: Add OpenAPI spec
Signed-off-by: jld3103 <jld3103yt@gmail.com>
Diffstat (limited to 'lib/private/legacy/OC_Helper.php')
-rw-r--r-- | lib/private/legacy/OC_Helper.php | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php index 8c8be0e1069..d96cb7bb4e9 100644 --- a/lib/private/legacy/OC_Helper.php +++ b/lib/private/legacy/OC_Helper.php @@ -54,6 +54,18 @@ use Psr\Log\LoggerInterface; /** * Collection of useful functions + * + * @psalm-type StorageInfo = array{ + * free: float|int, + * mountPoint: string, + * mountType: string, + * owner: string, + * ownerDisplayName: string, + * quota: float|int, + * relative: float|int, + * total: float|int, + * used: float|int, + * } */ class OC_Helper { private static $templateManager; @@ -458,7 +470,8 @@ class OC_Helper { * @param \OCP\Files\FileInfo $rootInfo (optional) * @param bool $includeMountPoints whether to include mount points in the size calculation * @param bool $useCache whether to use the cached quota values - * @return array + * @psalm-suppress LessSpecificReturnStatement Legacy code outputs weird types - manually validated that they are correct + * @return StorageInfo * @throws \OCP\Files\NotFoundException */ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoints = true, $useCache = true) { @@ -491,8 +504,9 @@ class OC_Helper { } $used = $rootInfo->getSize($includeMountPoints); if ($used < 0) { - $used = 0; + $used = 0.0; } + /** @var int|float $quota */ $quota = \OCP\Files\FileInfo::SPACE_UNLIMITED; $mount = $rootInfo->getMountPoint(); $storage = $mount->getStorage(); @@ -523,6 +537,9 @@ class OC_Helper { } try { $free = $sourceStorage->free_space($rootInfo->getInternalPath()); + if (is_bool($free)) { + $free = 0.0; + } } catch (\Exception $e) { if ($path === "") { throw $e; @@ -549,6 +566,7 @@ class OC_Helper { $relative = 0; } + /** @var string $ownerId */ $ownerId = $storage->getOwner($path); $ownerDisplayName = ''; if ($ownerId) { @@ -580,15 +598,20 @@ class OC_Helper { /** * Get storage info including all mount points and quota + * + * @psalm-suppress LessSpecificReturnStatement Legacy code outputs weird types - manually validated that they are correct + * @return StorageInfo */ private static function getGlobalStorageInfo(int|float $quota, IUser $user, IMountPoint $mount): array { $rootInfo = \OC\Files\Filesystem::getFileInfo('', 'ext'); + /** @var int|float $used */ $used = $rootInfo['size']; if ($used < 0) { - $used = 0; + $used = 0.0; } $total = $quota; + /** @var int|float $free */ $free = $quota - $used; if ($total > 0) { @@ -598,7 +621,7 @@ class OC_Helper { // prevent division by zero or error codes (negative values) $relative = round(($used / $total) * 10000) / 100; } else { - $relative = 0; + $relative = 0.0; } if (substr_count($mount->getMountPoint(), '/') < 3) { |