diff --git a/apps/dav/lib/Upload/ChunkingV2Plugin.php b/apps/dav/lib/Upload/ChunkingV2Plugin.php index 97ae51fbe380b..5c95cf1490635 100644 --- a/apps/dav/lib/Upload/ChunkingV2Plugin.php +++ b/apps/dav/lib/Upload/ChunkingV2Plugin.php @@ -42,6 +42,7 @@ use OCP\ICacheFactory; use OCP\Lock\ILockingProvider; use Sabre\DAV\Exception\BadRequest; +use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\InsufficientStorage; use Sabre\DAV\Exception\NotFound; use Sabre\DAV\Exception\PreconditionFailed; @@ -143,6 +144,25 @@ public function afterMkcol(RequestInterface $request, ResponseInterface $respons } public function beforePut(RequestInterface $request, ResponseInterface $response): bool { + if ($request->getHeader('OC-File-Type') == 1) { + // TODO: store default value in global location + $allowSymlinks = \OC::$server->get(\OC\AllConfig::class)->getSystemValueBool( + 'localstorage.allowsymlinks', false); + if (!$allowSymlinks) { + throw new Forbidden("Server does not allow the creation of symlinks!"); + } + $symlinkPath = $request->getPath(); + $symlinkTarget = $request->getBodyAsString(); + $parentNode = $this->server->tree->getNodeForPath(dirname($symlinkPath)); + if(!$parentNode instanceof \OCA\DAV\Connector\Sabre\Directory) { + throw new Exception("Unable to upload '$symlinkPath' because the remote directory does not support symlink creation!"); + } + $etag = $parentNode->createSymlink(basename($symlinkPath), $symlinkTarget); + $response->setHeader("OC-ETag", $etag); + $response->setStatus(201); + $this->server->sapi->sendResponse($response); + return false; + } try { $this->prepareUpload(dirname($request->getPath())); $this->checkPrerequisites();