Skip to content

Commit eed02ab

Browse files
committed
feature(dav/upload): Add symlink single-file upload to ChunkingV2Plugin
1 parent 301b999 commit eed02ab

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

apps/dav/lib/Upload/ChunkingV2Plugin.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use OCP\ICacheFactory;
4343
use OCP\Lock\ILockingProvider;
4444
use Sabre\DAV\Exception\BadRequest;
45+
use Sabre\DAV\Exception\Forbidden;
4546
use Sabre\DAV\Exception\InsufficientStorage;
4647
use Sabre\DAV\Exception\NotFound;
4748
use Sabre\DAV\Exception\PreconditionFailed;
@@ -143,6 +144,25 @@ public function afterMkcol(RequestInterface $request, ResponseInterface $respons
143144
}
144145

145146
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+
}
146166
try {
147167
$this->prepareUpload(dirname($request->getPath()));
148168
$this->checkPrerequisites();

0 commit comments

Comments
 (0)