From 29fc48e083fd53a7d25baaa197237fac5dcb005e Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 13 May 2026 10:38:18 +0200 Subject: [PATCH] fix(OC_Helper): properly calculate quota of shared storages - resolves https://github.com/nextcloud/server/issues/55659 First we need to properly handle shared storages, because there the quota is the quota of the user who owns the nodes, not the user who shared the nodes. Second if no user can be fetched then we cannot get the global storage info, thus in this case (public share?) we need to safe-guard. Signed-off-by: Ferdinand Thiessen --- build/psalm-baseline.xml | 3 --- lib/private/legacy/OC_Helper.php | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index da8022aed5975..da9e160cbeda8 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -4241,9 +4241,6 @@ - - - diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php index 9c85955bd1fe1..ad736b8218bfd 100644 --- a/lib/private/legacy/OC_Helper.php +++ b/lib/private/legacy/OC_Helper.php @@ -8,6 +8,7 @@ use bantu\IniGetWrapper\IniGetWrapper; use OC\Files\FilenameValidator; use OC\Files\Filesystem; +use OC\Files\ObjectStore\HomeObjectStoreStorage; use OC\Files\Storage\Home; use OC\Files\Storage\Wrapper\Quota; use OC\SystemConfig; @@ -15,6 +16,7 @@ use OCP\Files\FileInfo; use OCP\Files\Mount\IMountPoint; use OCP\Files\NotFoundException; +use OCP\Files\Storage\ISharedStorage; use OCP\IBinaryFinder; use OCP\ICacheFactory; use OCP\IConfig; @@ -190,16 +192,23 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin self::$quotaIncludeExternalStorage = false; } if (self::$quotaIncludeExternalStorage) { - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') + if ($storage->instanceOfStorage(ISharedStorage::class)) { + // we must use the shared nodes owner, + // because if user A shared a file with user B and B shares this again, + // then the share initiator is user B but the quota that this counts in is user A's quota. + /** @var ISharedStorage $storage */ + $user = $storage->getShare()->getNode()->getOwner(); + } elseif ( + $storage->instanceOfStorage('\OC\Files\Storage\Home') || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') ) { - /** @var Home $storage */ + /** @var Home|HomeObjectStoreStorage $storage */ $user = $storage->getUser(); } else { $user = Server::get(IUserSession::class)->getUser(); } $quota = $user?->getQuotaBytes() ?? FileInfo::SPACE_UNKNOWN; - if ($quota !== FileInfo::SPACE_UNLIMITED) { + if ($user !== null && $quota !== FileInfo::SPACE_UNLIMITED) { // always get free space / total space from root + mount points return self::getGlobalStorageInfo($quota, $user, $mount); } @@ -207,7 +216,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin // TODO: need a better way to get total space from storage if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) { - /** @var Quota $storage */ + /** @var Quota $sourceStorage */ $quota = $sourceStorage->getQuota(); } try {