diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php index 76959f6f01ea3..f5338112b213f 100644 --- a/lib/private/Files/SetupManager.php +++ b/lib/private/Files/SetupManager.php @@ -209,20 +209,6 @@ function ($mountPoint, IStorage $storage, IMountPoint $mount) use ($reSharingEna return $storage; }, 50, $existingMounts); - $quotaIncludeExternal = $this->config->getSystemValue('quota_include_external_storage', false); - $this->storageFactory->addStorageWrapper(Quota::class, function ($mountPoint, $storage, IMountPoint $mount) use ($quotaIncludeExternal) { - // set up quota for home storages, even for other users - // which can happen when using sharing - if ($mount instanceof HomeMountPoint) { - $user = $mount->getUser(); - return new Quota(['storage' => $storage, 'quotaCallback' => function () use ($user) { - return $user->getQuotaBytes(); - }, 'root' => 'files', 'include_external_storage' => $quotaIncludeExternal]); - } - - return $storage; - }, 50, $existingMounts); - $this->storageFactory->addStorageWrapper('readonly', function (string $mountPoint, IStorage $storage, IMountPoint $mount) { /* * Do not allow any operations that modify the storage @@ -241,6 +227,28 @@ function ($mountPoint, IStorage $storage, IMountPoint $mount) use ($reSharingEna }, 50, $existingMounts); } + /** + * Some wrapper are inited after BeforeFileSystemSetupEvent, to permit + * custom apps to preventively register their own handler + * + * @param IMountPoint[] $existingMounts + */ + private function setupCustomizableWrappers(array $existingMounts): void { + $quotaIncludeExternal = $this->config->getSystemValue('quota_include_external_storage', false); + $this->storageFactory->addStorageWrapper(Quota::class, function ($mountPoint, $storage, IMountPoint $mount) use ($quotaIncludeExternal) { + // set up quota for home storages, even for other users + // which can happen when using sharing + if ($mount instanceof HomeMountPoint) { + $user = $mount->getUser(); + return new Quota(['storage' => $storage, 'quotaCallback' => function () use ($user) { + return $user->getQuotaBytes(); + }, 'root' => 'files', 'include_external_storage' => $quotaIncludeExternal]); + } + + return $storage; + }, 50, $existingMounts); + } + /** * Update the cached mounts for all non-authoritative mount providers for a user. */ @@ -328,6 +336,8 @@ private function oneTimeUserSetup(IUser $user): void { } } + $this->setupCustomizableWrappers($mounts); + $userDir = '/' . $user->getUID() . '/files'; Filesystem::initInternal($userDir); diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index b0ff0117b960f..02518c4e5927b 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -58,7 +58,7 @@ private function hasQuota(): bool { protected function getSize(string $path, ?IStorage $storage = null): int|float { if ($this->quotaIncludeExternalStorage) { - $rootInfo = Filesystem::getFileInfo('', 'ext'); + $rootInfo = Filesystem::getFileInfo($path, 'ext'); if ($rootInfo) { return $rootInfo->getSize(true); } diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php index 8e9135b185707..890fcfe9ca486 100644 --- a/lib/private/legacy/OC_Helper.php +++ b/lib/private/legacy/OC_Helper.php @@ -187,10 +187,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin if (!$rootInfo instanceof FileInfo) { throw new NotFoundException('The root directory of the user\'s files is missing'); } - $used = $rootInfo->getSize($includeMountPoints); - if ($used < 0) { - $used = 0.0; - } + /** @var int|float $quota */ $quota = FileInfo::SPACE_UNLIMITED; $mount = $rootInfo->getMountPoint(); @@ -226,7 +223,13 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) { /** @var Quota $sourceStorage */ $quota = $sourceStorage->getQuota(); + $used = $sourceStorage->getSize($path, $storage); + } else { + $used = $rootInfo->getSize($includeMountPoints); } + + $used = max($used, 0.0); + try { $free = $sourceStorage->free_space($rootInfo->getInternalPath()); if (is_bool($free)) {