Skip to content

Commit

Permalink
feature(dav/upload): Add symlink single-file upload to ChunkingV2Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
taminob committed Nov 7, 2023
1 parent 301b999 commit eed02ab
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions apps/dav/lib/Upload/ChunkingV2Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit eed02ab

Please sign in to comment.