Skip to content

Commit

Permalink
SymlinkPlugin/FilesPlugin: Fix httpGet and httpDelete for symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
taminob committed Nov 27, 2023
1 parent 53749a4 commit 24d5ee5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 5 additions & 3 deletions apps/dav/lib/Connector/Sabre/FilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,14 @@ public function handleDownloadToken(RequestInterface $request, ResponseInterface
public function httpGet(RequestInterface $request, ResponseInterface $response) {

Check notice

Code scanning / Psalm

MissingReturnType Note

Method OCA\DAV\Connector\Sabre\FilesPlugin::httpGet does not have a return type, expecting false|null
// only handle symlinks
$node = $this->tree->getNodeForPath($request->getPath());
if (!($node instanceof \OCP\Files\File && $this->symlinkManager->isSymlink($node))) {
if (!($node instanceof \OCA\DAV\Connector\Sabre\File && $this->symlinkManager->isSymlink($node->getFileInfo()))) {
return;
}

$response->addHeader('OC-File-Type', '1');
$response->setBody($node->getContent());
$response->setHeader('OC-File-Type', '1');
$response->setHeader('OC-ETag', $node->getEtag());
$response->setBody($node->get());
$response->setStatus(200);
// do not continue processing this request
return false;
}
Expand Down
9 changes: 6 additions & 3 deletions apps/dav/lib/Upload/SymlinkPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@ public function httpPut(RequestInterface $request, ResponseInterface $response):

public function httpDelete(RequestInterface $request, ResponseInterface $response): bool {
$path = $request->getPath();
$node = $this->server->tree->getNodeForPath(dirname($path));
if (!$node instanceof \OCA\DAV\Connector\Sabre\File) {
$node = $this->server->tree->getNodeForPath($path);
if (!$node instanceof \OCA\DAV\Connector\Sabre\Node) {
return true;
}
$info = $node->getFileInfo();
if ($this->symlinkManager->isSymlink($info)) {
$this->symlinkManager->deleteSymlink($info);
if (!$this->symlinkManager->deleteSymlink($info)) {
$symlinkName = $info->getName();
throw new \Sabre\DAV\Exception\NotFound("Unable to delete symlink '$symlinkName'!");
}
}
// always propagate to trigger deletion of regular file representing symlink in filesystem
return true;
Expand Down

0 comments on commit 24d5ee5

Please sign in to comment.