Skip to content

Commit d07ede9

Browse files
susnuxbackportbot[bot]
authored andcommitted
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 5b445c5 commit d07ede9

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

build/psalm-baseline.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4241,9 +4241,6 @@
42414241
<InternalMethod>
42424242
<code><![CDATA[getAbsolutePath]]></code>
42434243
</InternalMethod>
4244-
<UndefinedInterfaceMethod>
4245-
<code><![CDATA[getQuota]]></code>
4246-
</UndefinedInterfaceMethod>
42474244
</file>
42484245
<file src="lib/private/legacy/OC_User.php">
42494246
<UndefinedClass>

lib/private/legacy/OC_Helper.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
use bantu\IniGetWrapper\IniGetWrapper;
99
use OC\Files\FilenameValidator;
1010
use OC\Files\Filesystem;
11+
use OC\Files\ObjectStore\HomeObjectStoreStorage;
1112
use OC\Files\Storage\Home;
1213
use OC\Files\Storage\Wrapper\Quota;
1314
use OC\SystemConfig;
1415
use OCA\Files_Sharing\External\Storage;
1516
use OCP\Files\FileInfo;
1617
use OCP\Files\Mount\IMountPoint;
1718
use OCP\Files\NotFoundException;
19+
use OCP\Files\Storage\ISharedStorage;
1820
use OCP\IBinaryFinder;
1921
use OCP\ICacheFactory;
2022
use OCP\IConfig;
@@ -190,24 +192,31 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
190192
self::$quotaIncludeExternalStorage = false;
191193
}
192194
if (self::$quotaIncludeExternalStorage) {
193-
if ($storage->instanceOfStorage('\OC\Files\Storage\Home')
195+
if ($storage->instanceOfStorage(ISharedStorage::class)) {
196+
// we must use the shared nodes owner,
197+
// because if user A shared a file with user B and B shares this again,
198+
// then the share initiator is user B but the quota that this counts in is user A's quota.
199+
/** @var ISharedStorage $storage */
200+
$user = $storage->getShare()->getNode()->getOwner();
201+
} elseif (
202+
$storage->instanceOfStorage('\OC\Files\Storage\Home')
194203
|| $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')
195204
) {
196-
/** @var Home $storage */
205+
/** @var Home|HomeObjectStoreStorage $storage */
197206
$user = $storage->getUser();
198207
} else {
199208
$user = Server::get(IUserSession::class)->getUser();
200209
}
201210
$quota = $user?->getQuotaBytes() ?? FileInfo::SPACE_UNKNOWN;
202-
if ($quota !== FileInfo::SPACE_UNLIMITED) {
211+
if ($user !== null && $quota !== FileInfo::SPACE_UNLIMITED) {
203212
// always get free space / total space from root + mount points
204213
return self::getGlobalStorageInfo($quota, $user, $mount);
205214
}
206215
}
207216

208217
// TODO: need a better way to get total space from storage
209218
if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) {
210-
/** @var Quota $storage */
219+
/** @var Quota $sourceStorage */
211220
$quota = $sourceStorage->getQuota();
212221
}
213222
try {

0 commit comments

Comments
 (0)