Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions lib/private/Files/SetupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*/
Expand Down Expand Up @@ -328,6 +336,8 @@ private function oneTimeUserSetup(IUser $user): void {
}
}

$this->setupCustomizableWrappers($mounts);

$userDir = '/' . $user->getUID() . '/files';

Filesystem::initInternal($userDir);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/Wrapper/Quota.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 7 additions & 4 deletions lib/private/legacy/OC_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down