diff options
author | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2022-11-17 15:40:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-17 15:40:21 +0100 |
commit | 6868cfbc2e48c552bdf5abc5cfc9099b0f15c684 (patch) | |
tree | f413957362840369c24379546df4f326043685bd | |
parent | 301af07e2f4cb506512899b7b4783db8b7975ee9 (diff) | |
parent | feafa63afbe84dc2ca4483e02412337a61ff99e9 (diff) | |
download | nextcloud-server-6868cfbc2e48c552bdf5abc5cfc9099b0f15c684.tar.gz nextcloud-server-6868cfbc2e48c552bdf5abc5cfc9099b0f15c684.zip |
Merge pull request #35009 from nextcloud/fix/check-quota-on-copy
Check quota on file copy
-rw-r--r-- | apps/dav/lib/Connector/Sabre/QuotaPlugin.php | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/apps/dav/lib/Connector/Sabre/QuotaPlugin.php b/apps/dav/lib/Connector/Sabre/QuotaPlugin.php index f2b652e3320..7c6bf64602e 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); } /** @@ -131,7 +131,42 @@ class QuotaPlugin extends \Sabre\DAV\ServerPlugin { $destinationNode = $this->server->tree->getNodeForPath($destination); $path = $destinationNode->getPath(); } else { - $parentNode = $this->server->tree->getNodeForPath(dirname($destination)); + $parent = dirname($destination); + if ($parent === '.') { + $parent = ''; + } + $parentNode = $this->server->tree->getNodeForPath($parent); + $path = $parentNode->getPath(); + } + + 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); + if (!$destinationNode instanceof Node) { + return false; + } + $path = $destinationNode->getPath(); + } else { + $parent = dirname($destinationPath); + if ($parent === '.') { + $parent = ''; + } + $parentNode = $this->server->tree->getNodeForPath($parent); + if (!$parentNode instanceof Node) { + return false; + } $path = $parentNode->getPath(); } |