|
42 | 42 | use OCP\ICacheFactory; |
43 | 43 | use OCP\Lock\ILockingProvider; |
44 | 44 | use Sabre\DAV\Exception\BadRequest; |
| 45 | +use Sabre\DAV\Exception\Forbidden; |
45 | 46 | use Sabre\DAV\Exception\InsufficientStorage; |
46 | 47 | use Sabre\DAV\Exception\NotFound; |
47 | 48 | use Sabre\DAV\Exception\PreconditionFailed; |
@@ -143,6 +144,25 @@ public function afterMkcol(RequestInterface $request, ResponseInterface $respons |
143 | 144 | } |
144 | 145 |
|
145 | 146 | public function beforePut(RequestInterface $request, ResponseInterface $response): bool { |
| 147 | + if ($request->getHeader('OC-File-Type') == 1) { |
| 148 | + // TODO: store default value in global location |
| 149 | + $allowSymlinks = \OC::$server->get(\OC\AllConfig::class)->getSystemValueBool( |
| 150 | + 'localstorage.allowsymlinks', false); |
| 151 | + if (!$allowSymlinks) { |
| 152 | + throw new Forbidden("Server does not allow the creation of symlinks!"); |
| 153 | + } |
| 154 | + $symlinkPath = $request->getPath(); |
| 155 | + $symlinkTarget = $request->getBodyAsString(); |
| 156 | + $parentNode = $this->server->tree->getNodeForPath(dirname($symlinkPath)); |
| 157 | + if(!$parentNode instanceof \OCA\DAV\Connector\Sabre\Directory) { |
| 158 | + throw new Exception("Unable to upload '$symlinkPath' because the remote directory does not support symlink creation!"); |
| 159 | + } |
| 160 | + $etag = $parentNode->createSymlink(basename($symlinkPath), $symlinkTarget); |
| 161 | + $response->setHeader("OC-ETag", $etag); |
| 162 | + $response->setStatus(201); |
| 163 | + $this->server->sapi->sendResponse($response); |
| 164 | + return false; |
| 165 | + } |
146 | 166 | try { |
147 | 167 | $this->prepareUpload(dirname($request->getPath())); |
148 | 168 | $this->checkPrerequisites(); |
|
0 commit comments