Skip to content

Commit 7174d9d

Browse files
authored
Merge pull request #60535 from nextcloud/backport/60341/stable33
[stable33] fix(OC_Helper): properly calculate quota of shared storages
2 parents e01d0c4 + 7a18c59 commit 7174d9d

2 files changed

Lines changed: 17 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: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
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;
16+
use OCP\Files\Storage\ISharedStorage;
1217
use OCP\IBinaryFinder;
1318
use OCP\ICacheFactory;
1419
use OCP\IUser;
@@ -181,24 +186,31 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
181186
self::$quotaIncludeExternalStorage = false;
182187
}
183188
if (self::$quotaIncludeExternalStorage) {
184-
if ($storage->instanceOfStorage('\OC\Files\Storage\Home')
189+
if ($storage->instanceOfStorage(ISharedStorage::class)) {
190+
// we must use the shared nodes owner,
191+
// because if user A shared a file with user B and B shares this again,
192+
// then the share initiator is user B but the quota that this counts in is user A's quota.
193+
/** @var ISharedStorage $storage */
194+
$user = $storage->getShare()->getNode()->getOwner();
195+
} elseif (
196+
$storage->instanceOfStorage('\OC\Files\Storage\Home')
185197
|| $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')
186198
) {
187-
/** @var \OC\Files\Storage\Home $storage */
199+
/** @var Home|HomeObjectStoreStorage $storage */
188200
$user = $storage->getUser();
189201
} else {
190202
$user = \OC::$server->getUserSession()->getUser();
191203
}
192-
$quota = $user?->getQuotaBytes() ?? \OCP\Files\FileInfo::SPACE_UNKNOWN;
193-
if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
204+
$quota = $user?->getQuotaBytes() ?? FileInfo::SPACE_UNKNOWN;
205+
if ($user !== null && $quota !== FileInfo::SPACE_UNLIMITED) {
194206
// always get free space / total space from root + mount points
195207
return self::getGlobalStorageInfo($quota, $user, $mount);
196208
}
197209
}
198210

199211
// TODO: need a better way to get total space from storage
200212
if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) {
201-
/** @var \OC\Files\Storage\Wrapper\Quota $storage */
213+
/** @var Quota $sourceStorage */
202214
$quota = $sourceStorage->getQuota();
203215
}
204216
try {

0 commit comments

Comments
 (0)