aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreta <gretadoci@gmail.com>2022-11-23 10:39:04 +0100
committerGitHub <noreply@github.com>2022-11-23 10:39:04 +0100
commit69d59d3f663343e62788c0aa85f89ed54cd1d5de (patch)
tree71316801eb08c4064db0ab6a5ddc3848bdc2f3f6
parentc610950ccd93cb13b41d76acd800d006740b27ca (diff)
parentd07c5c6d2dc782aef603b09a333112752bb03dd3 (diff)
downloadnextcloud-server-69d59d3f663343e62788c0aa85f89ed54cd1d5de.tar.gz
nextcloud-server-69d59d3f663343e62788c0aa85f89ed54cd1d5de.zip
Merge pull request #35328 from nextcloud/backport/35009/stable24
[stable24] Check quota on file copy
-rw-r--r--apps/dav/lib/Connector/Sabre/QuotaPlugin.php39
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();
}