|
45 | 45 | use OCP\IConfig; |
46 | 46 | use OCP\Lock\ILockingProvider; |
47 | 47 | use Sabre\DAV\Exception\BadRequest; |
| 48 | +use Sabre\DAV\Exception\Forbidden; |
48 | 49 | use Sabre\DAV\Exception\InsufficientStorage; |
49 | 50 | use Sabre\DAV\Exception\MethodNotAllowed; |
50 | 51 | use Sabre\DAV\Exception\NotFound; |
@@ -118,18 +119,26 @@ public function beforeGet(RequestInterface $request) { |
118 | 119 | * @param string $path |
119 | 120 | * @param bool $createIfNotExists |
120 | 121 | * @return FutureFile|UploadFile|ICollection|INode |
| 122 | + * @throws Forbidden if the file already exists, but is not updateable |
121 | 123 | */ |
122 | 124 | private function getUploadFile(string $path, bool $createIfNotExists = false) { |
123 | 125 | try { |
124 | 126 | $actualFile = $this->server->tree->getNodeForPath($path); |
125 | | - // Only directly upload to the target file if it is on the same storage |
126 | | - // There may be further potential to optimize here by also uploading |
127 | | - // to other storages directly. This would require to also carefully pick |
128 | | - // the storage/path used in getStorage() |
129 | | - if ($actualFile instanceof File && $this->uploadFolder->getStorage()->getId() === $actualFile->getNode()->getStorage()->getId()) { |
130 | | - return $actualFile; |
| 127 | + if ($actualFile instanceof File) { |
| 128 | + $node = $actualFile->getNode(); |
| 129 | + // check that the node has update permissions |
| 130 | + if (!$node->isUpdateable()) { |
| 131 | + throw new Forbidden(); |
| 132 | + } |
| 133 | + // Only directly upload to the target file if it is on the same storage |
| 134 | + // There may be further potential to optimize here by also uploading |
| 135 | + // to other storages directly. This would require to also carefully pick |
| 136 | + // the storage/path used in getStorage() |
| 137 | + if ($this->uploadFolder->getStorage()->getId() === $node->getStorage()->getId()) { |
| 138 | + return $actualFile; |
| 139 | + } |
131 | 140 | } |
132 | | - } catch (NotFound $e) { |
| 141 | + } catch (NotFound) { |
133 | 142 | // If there is no target file we upload to the upload folder first |
134 | 143 | } |
135 | 144 |
|
|
0 commit comments