Skip to content

Commit f0d32c8

Browse files
committed
fix(OC_Helper): properly calculate quota of shared storages
- resolves #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 <opensource@fthiessen.de>
1 parent eec0f10 commit f0d32c8

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

build/psalm-baseline.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4207,9 +4207,6 @@
42074207
<InternalMethod>
42084208
<code><![CDATA[getAbsolutePath]]></code>
42094209
</InternalMethod>
4210-
<UndefinedInterfaceMethod>
4211-
<code><![CDATA[getQuota]]></code>
4212-
</UndefinedInterfaceMethod>
42134210
</file>
42144211
<file src="lib/private/legacy/OC_User.php">
42154212
<UndefinedClass>

lib/private/legacy/OC_Helper.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
use bantu\IniGetWrapper\IniGetWrapper;
99
use OC\Files\FilenameValidator;
1010
use OC\Files\Filesystem;
11+
use OC\Files\ObjectStore\HomeObjectStoreStorage;
12+
use OC\Files\Storage\Home;
13+
use OC\Files\Storage\Wrapper\Quota;
14+
use OCP\Files\FileInfo;
1115
use OCP\Files\Mount\IMountPoint;
1216
use OCP\IBinaryFinder;
1317
use OCP\ICacheFactory;
@@ -181,24 +185,31 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
181185
self::$quotaIncludeExternalStorage = false;
182186
}
183187
if (self::$quotaIncludeExternalStorage) {
184-
if ($storage->instanceOfStorage('\OC\Files\Storage\Home')
188+
if ($storage->instanceOfStorage(ISharedStorage::class)) {
189+
// we must use the shared nodes owner,
190+
// because if user A shared a file with user B and B shares this again,
191+
// then the share initiator is user B but the quota that this counts in is user A's quota.
192+
/** @var ISharedStorage $storage */
193+
$user = $storage->getShare()->getNode()->getOwner();
194+
} elseif (
195+
$storage->instanceOfStorage('\OC\Files\Storage\Home')
185196
|| $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')
186197
) {
187-
/** @var \OC\Files\Storage\Home $storage */
198+
/** @var Home|HomeObjectStoreStorage $storage */
188199
$user = $storage->getUser();
189200
} else {
190201
$user = \OC::$server->getUserSession()->getUser();
191202
}
192-
$quota = $user?->getQuotaBytes() ?? \OCP\Files\FileInfo::SPACE_UNKNOWN;
193-
if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
203+
$quota = $user?->getQuotaBytes() ?? FileInfo::SPACE_UNKNOWN;
204+
if ($user !== null && $quota !== FileInfo::SPACE_UNLIMITED) {
194205
// always get free space / total space from root + mount points
195206
return self::getGlobalStorageInfo($quota, $user, $mount);
196207
}
197208
}
198209

199210
// TODO: need a better way to get total space from storage
200211
if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) {
201-
/** @var \OC\Files\Storage\Wrapper\Quota $storage */
212+
/** @var Quota $sourceStorage */
202213
$quota = $sourceStorage->getQuota();
203214
}
204215
try {

0 commit comments

Comments
 (0)