diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-11-07 17:25:42 +0100 |
---|---|---|
committer | Côme Chilliet (Rebase PR Action) <come-nc@users.noreply.github.com> | 2022-11-17 13:22:49 +0000 |
commit | 5ed840ed2361a148c60e9900cc6524827e987b17 (patch) | |
tree | fb36007294a03c4dc157ead5c182b0cc2a8261cd /apps/dav | |
parent | 301af07e2f4cb506512899b7b4783db8b7975ee9 (diff) | |
download | nextcloud-server-5ed840ed2361a148c60e9900cc6524827e987b17.tar.gz nextcloud-server-5ed840ed2361a148c60e9900cc6524827e987b17.zip |
Check quota on file copy
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/lib/Connector/Sabre/QuotaPlugin.php | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/apps/dav/lib/Connector/Sabre/QuotaPlugin.php b/apps/dav/lib/Connector/Sabre/QuotaPlugin.php index f2b652e3320..0e5ffe51728 100644 --- a/apps/dav/lib/Connector/Sabre/QuotaPlugin.php +++ b/apps/dav/lib/Connector/Sabre/QuotaPlugin.php @@ -44,7 +44,6 @@ use Sabre\DAV\INode; * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License */ class QuotaPlugin extends \Sabre\DAV\ServerPlugin { - /** @var \OC\Files\View */ private $view; @@ -79,6 +78,7 @@ class QuotaPlugin extends \Sabre\DAV\ServerPlugin { $server->on('beforeWriteContent', [$this, 'beforeWriteContent'], 10); $server->on('beforeCreateFile', [$this, 'beforeCreateFile'], 10); $server->on('beforeMove', [$this, 'beforeMove'], 10); + $server->on('beforeCopy', [$this, 'beforeCopy'], 10); } /** @@ -138,6 +138,27 @@ class QuotaPlugin extends \Sabre\DAV\ServerPlugin { return $this->checkQuota($path, $sourceNode->getSize()); } + /** + * Check quota on the target destination before a copy. + */ + public function beforeCopy(string $sourcePath, string $destinationPath): bool { + $sourceNode = $this->server->tree->getNodeForPath($sourcePath); + if (!$sourceNode instanceof Node) { + return false; + } + + // get target node for proper path conversion + if ($this->server->tree->nodeExists($destinationPath)) { + $destinationNode = $this->server->tree->getNodeForPath($destinationPath); + $path = $destinationNode->getPath(); + } else { + $parentNode = $this->server->tree->getNodeForPath(dirname($destinationPath)); + $path = $parentNode->getPath(); + } + + return $this->checkQuota($path, $sourceNode->getSize()); + } + /** * This method is called before any HTTP method and validates there is enough free space to store the file |