|
29 | 29 | use OCP\IConfig; |
30 | 30 | use OCP\Lock\ILockingProvider; |
31 | 31 | use Sabre\DAV\Exception\BadRequest; |
| 32 | +use Sabre\DAV\Exception\Forbidden; |
32 | 33 | use Sabre\DAV\Exception\InsufficientStorage; |
33 | 34 | use Sabre\DAV\Exception\MethodNotAllowed; |
34 | 35 | use Sabre\DAV\Exception\NotFound; |
@@ -108,18 +109,26 @@ public function forbiddenMethod(RequestInterface $request) { |
108 | 109 | * @param string $path |
109 | 110 | * @param bool $createIfNotExists |
110 | 111 | * @return FutureFile|UploadFile|ICollection|INode |
| 112 | + * @throws Forbidden if the file already exists, but is not updateable |
111 | 113 | */ |
112 | 114 | private function getUploadFile(string $path, bool $createIfNotExists = false) { |
113 | 115 | try { |
114 | 116 | $actualFile = $this->server->tree->getNodeForPath($path); |
115 | | - // Only directly upload to the target file if it is on the same storage |
116 | | - // There may be further potential to optimize here by also uploading |
117 | | - // to other storages directly. This would require to also carefully pick |
118 | | - // the storage/path used in getStorage() |
119 | | - if ($actualFile instanceof File && $this->uploadFolder->getStorage()->getId() === $actualFile->getNode()->getStorage()->getId()) { |
120 | | - return $actualFile; |
| 117 | + if ($actualFile instanceof File) { |
| 118 | + $node = $actualFile->getNode(); |
| 119 | + // check that the node has update permissions |
| 120 | + if (!$node->isUpdateable()) { |
| 121 | + throw new Forbidden(); |
| 122 | + } |
| 123 | + // Only directly upload to the target file if it is on the same storage |
| 124 | + // There may be further potential to optimize here by also uploading |
| 125 | + // to other storages directly. This would require to also carefully pick |
| 126 | + // the storage/path used in getStorage() |
| 127 | + if ($this->uploadFolder->getStorage()->getId() === $node->getStorage()->getId()) { |
| 128 | + return $actualFile; |
| 129 | + } |
121 | 130 | } |
122 | | - } catch (NotFound $e) { |
| 131 | + } catch (NotFound) { |
123 | 132 | // If there is no target file we upload to the upload folder first |
124 | 133 | } |
125 | 134 |
|
|
0 commit comments