Skip to content

Commit

Permalink
SymlinkPlugin: Fix copying of symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
taminob committed Dec 14, 2023
1 parent 7d7fe3e commit 6791bf2
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion apps/dav/lib/Upload/SymlinkPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 6791bf2

Please sign in to comment.