Skip to content

Commit 2166494

Browse files
committed
SymlinkPlugin: Fix copying of symlinks
Signed-off-by: Tamino Bauknecht <[email protected]>
1 parent 1a252ea commit 2166494

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

apps/dav/lib/Upload/SymlinkPlugin.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function initialize(Server $server): void {
5656
$server->on('method:PUT', [$this, 'httpPut']);
5757
$server->on('method:DELETE', [$this, 'httpDelete']);
5858
$server->on('afterMove', [$this, 'afterMove']);
59+
$server->on('afterCopy', [$this, 'afterCopy']);
5960

6061
$this->server = $server;
6162
}
@@ -117,7 +118,7 @@ public function httpDelete(RequestInterface $request, ResponseInterface $respons
117118
return true;
118119
}
119120

120-
public function afterMove(string $source, string $destination) {
121+
public function afterMove(string $source, string $destination): void {
121122
// source node does not exist anymore, thus use still existing parent
122123
$sourceParentNode = dirname($source);
123124
$sourceParentNode = $this->server->tree->getNodeForPath($sourceParentNode);
@@ -145,4 +146,24 @@ public function afterMove(string $source, string $destination) {
145146
$this->symlinkManager->deleteSymlink($destinationInfo);
146147
}
147148
}
149+
150+
public function afterCopy(string $source, string $destination): void {
151+
$sourceNode = $this->server->tree->getNodeForPath($source);
152+
if (!$sourceNode instanceof \OCA\DAV\Connector\Sabre\Node) {
153+
throw new \Sabre\DAV\Exception\NotImplemented(
154+
'Unable to check if copied file is a symlink!');
155+
}
156+
$destinationNode = $this->server->tree->getNodeForPath($destination);
157+
if (!$destinationNode instanceof \OCA\DAV\Connector\Sabre\Node) {
158+
throw new \Sabre\DAV\Exception\NotImplemented(
159+
'Unable to set symlink information on copy destination!');
160+
}
161+
162+
$sourceInfo = $sourceNode->getFileInfo();
163+
$destinationInfo = $destinationNode->getFileInfo();
164+
165+
if ($this->symlinkManager->isSymlink($sourceInfo)) {
166+
$this->symlinkManager->storeSymlink($destinationInfo);
167+
}
168+
}
148169
}

0 commit comments

Comments
 (0)