From 2166494a539ed1d1728e1864c896d0e729d3ab4e Mon Sep 17 00:00:00 2001 From: Tamino Bauknecht Date: Thu, 14 Dec 2023 20:09:54 +0100 Subject: [PATCH] SymlinkPlugin: Fix copying of symlinks Signed-off-by: Tamino Bauknecht --- apps/dav/lib/Upload/SymlinkPlugin.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/dav/lib/Upload/SymlinkPlugin.php b/apps/dav/lib/Upload/SymlinkPlugin.php index e619f52aa551a..b4123e9ff0a58 100644 --- a/apps/dav/lib/Upload/SymlinkPlugin.php +++ b/apps/dav/lib/Upload/SymlinkPlugin.php @@ -56,6 +56,7 @@ public function initialize(Server $server): void { $server->on('method:PUT', [$this, 'httpPut']); $server->on('method:DELETE', [$this, 'httpDelete']); $server->on('afterMove', [$this, 'afterMove']); + $server->on('afterCopy', [$this, 'afterCopy']); $this->server = $server; } @@ -117,7 +118,7 @@ public function httpDelete(RequestInterface $request, ResponseInterface $respons return true; } - public function afterMove(string $source, string $destination) { + public function afterMove(string $source, string $destination): void { // source node does not exist anymore, thus use still existing parent $sourceParentNode = dirname($source); $sourceParentNode = $this->server->tree->getNodeForPath($sourceParentNode); @@ -145,4 +146,24 @@ public function afterMove(string $source, string $destination) { $this->symlinkManager->deleteSymlink($destinationInfo); } } + + public function afterCopy(string $source, string $destination): void { + $sourceNode = $this->server->tree->getNodeForPath($source); + if (!$sourceNode instanceof \OCA\DAV\Connector\Sabre\Node) { + throw new \Sabre\DAV\Exception\NotImplemented( + 'Unable to check if copied file is a symlink!'); + } + $destinationNode = $this->server->tree->getNodeForPath($destination); + if (!$destinationNode instanceof \OCA\DAV\Connector\Sabre\Node) { + throw new \Sabre\DAV\Exception\NotImplemented( + 'Unable to set symlink information on copy destination!'); + } + + $sourceInfo = $sourceNode->getFileInfo(); + $destinationInfo = $destinationNode->getFileInfo(); + + if ($this->symlinkManager->isSymlink($sourceInfo)) { + $this->symlinkManager->storeSymlink($destinationInfo); + } + } }