Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Check quota on file copy
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc authored and backportbot-nextcloud[bot] committed Nov 22, 2022
commit 6638b5411e3f4a46c91e977d53fe5e03b5734ea6
23 changes: 22 additions & 1 deletion apps/dav/lib/Connector/Sabre/QuotaPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class QuotaPlugin extends \Sabre\DAV\ServerPlugin {

/** @var \OC\Files\View */
private $view;

Expand Down Expand Up @@ -79,6 +78,7 @@ public function initialize(\Sabre\DAV\Server $server) {
$server->on('beforeWriteContent', [$this, 'beforeWriteContent'], 10);
$server->on('beforeCreateFile', [$this, 'beforeCreateFile'], 10);
$server->on('beforeMove', [$this, 'beforeMove'], 10);
$server->on('beforeCopy', [$this, 'beforeCopy'], 10);
}

/**
Expand Down Expand Up @@ -138,6 +138,27 @@ public function beforeMove($source, $destination) {
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
Expand Down