Skip to content

Commit dd4c3dd

Browse files
authored
Merge pull request #35329 from nextcloud/backport/35232/stable23
[stable23] Check quota on file copy
2 parents 80c63dc + fe92aec commit dd4c3dd

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

apps/dav/lib/Connector/Sabre/QuotaPlugin.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
4545
*/
4646
class QuotaPlugin extends \Sabre\DAV\ServerPlugin {
47-
4847
/** @var \OC\Files\View */
4948
private $view;
5049

@@ -79,6 +78,7 @@ public function initialize(\Sabre\DAV\Server $server) {
7978
$server->on('beforeWriteContent', [$this, 'beforeWriteContent'], 10);
8079
$server->on('beforeCreateFile', [$this, 'beforeCreateFile'], 10);
8180
$server->on('beforeMove', [$this, 'beforeMove'], 10);
81+
$server->on('beforeCopy', [$this, 'beforeCopy'], 10);
8282
}
8383

8484
/**
@@ -131,7 +131,42 @@ public function beforeMove($source, $destination) {
131131
$destinationNode = $this->server->tree->getNodeForPath($destination);
132132
$path = $destinationNode->getPath();
133133
} else {
134-
$parentNode = $this->server->tree->getNodeForPath(dirname($destination));
134+
$parent = dirname($destination);
135+
if ($parent === '.') {
136+
$parent = '';
137+
}
138+
$parentNode = $this->server->tree->getNodeForPath($parent);
139+
$path = $parentNode->getPath();
140+
}
141+
142+
return $this->checkQuota($path, $sourceNode->getSize());
143+
}
144+
145+
/**
146+
* Check quota on the target destination before a copy.
147+
*/
148+
public function beforeCopy(string $sourcePath, string $destinationPath): bool {
149+
$sourceNode = $this->server->tree->getNodeForPath($sourcePath);
150+
if (!$sourceNode instanceof Node) {
151+
return false;
152+
}
153+
154+
// get target node for proper path conversion
155+
if ($this->server->tree->nodeExists($destinationPath)) {
156+
$destinationNode = $this->server->tree->getNodeForPath($destinationPath);
157+
if (!$destinationNode instanceof Node) {
158+
return false;
159+
}
160+
$path = $destinationNode->getPath();
161+
} else {
162+
$parent = dirname($destinationPath);
163+
if ($parent === '.') {
164+
$parent = '';
165+
}
166+
$parentNode = $this->server->tree->getNodeForPath($parent);
167+
if (!$parentNode instanceof Node) {
168+
return false;
169+
}
135170
$path = $parentNode->getPath();
136171
}
137172

0 commit comments

Comments
 (0)