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); + } + } }