diff --git a/apps/dav/lib/Connector/Sabre/QuotaPlugin.php b/apps/dav/lib/Connector/Sabre/QuotaPlugin.php index bbb378edc9bde..2620cadcd5b31 100644 --- a/apps/dav/lib/Connector/Sabre/QuotaPlugin.php +++ b/apps/dav/lib/Connector/Sabre/QuotaPlugin.php @@ -217,12 +217,25 @@ public function checkQuota(string $path, $length = null, $isDir = false) { // Strip any duplicate slashes $path = str_replace('//', '/', $path); + // TODO: I suspect the below existence check more properly belongs in + // beforeCreateFile(), similar to what already exists in + // beforeCopy and beforeMove() + // NOTE: && or || here is equivalent in terms of outcome (but && our intention) + // because only other times the full path SHOULD get to us here is when + // existence has already been confirmed - see beforeCopy() & beforeMove()) + if (($req->getHeader('Destination') === null || $req->getHeader('Destination') === '') && !$this->server->tree->nodeExists($path)) { + $path = dirname($path); + } + + $targetOwner = $this->view->getOwner($path); $freeSpace = $this->getFreeSpace($path); if ($freeSpace >= 0 && $length > $freeSpace) { + if ($targetOwner !== \OC_User::getUser()) { + throw new InsufficientStorage("Quota exceeded in $path (owner: $targetOwner), $length required, $freeSpace available"); + } if ($isDir) { throw new InsufficientStorage("Insufficient space in $path. $freeSpace available. Cannot create directory"); } - throw new InsufficientStorage("Insufficient space in $path, $length required, $freeSpace available"); } } diff --git a/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php index 6fe2d6ccabe03..af723f71e8c91 100644 --- a/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php @@ -13,6 +13,11 @@ use OCP\Files\FileInfo; use Test\TestCase; +/** + * Class QuotaPluginTest + * + * @group DB + */ class QuotaPluginTest extends TestCase { private \Sabre\DAV\Server $server;