|  | 
| 44 | 44 |  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License | 
| 45 | 45 |  */ | 
| 46 | 46 | class QuotaPlugin extends \Sabre\DAV\ServerPlugin { | 
| 47 |  | - | 
| 48 | 47 | 	/** @var \OC\Files\View */ | 
| 49 | 48 | 	private $view; | 
| 50 | 49 | 
 | 
| @@ -79,6 +78,7 @@ public function initialize(\Sabre\DAV\Server $server) { | 
| 79 | 78 | 		$server->on('beforeWriteContent', [$this, 'beforeWriteContent'], 10); | 
| 80 | 79 | 		$server->on('beforeCreateFile', [$this, 'beforeCreateFile'], 10); | 
| 81 | 80 | 		$server->on('beforeMove', [$this, 'beforeMove'], 10); | 
|  | 81 | +		$server->on('beforeCopy', [$this, 'beforeCopy'], 10); | 
| 82 | 82 | 	} | 
| 83 | 83 | 
 | 
| 84 | 84 | 	/** | 
| @@ -131,7 +131,42 @@ public function beforeMove($source, $destination) { | 
| 131 | 131 | 			$destinationNode = $this->server->tree->getNodeForPath($destination); | 
| 132 | 132 | 			$path = $destinationNode->getPath(); | 
| 133 | 133 | 		} 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 | +			} | 
| 135 | 170 | 			$path = $parentNode->getPath(); | 
| 136 | 171 | 		} | 
| 137 | 172 | 
 | 
|  | 
0 commit comments