Skip to content

Commit

Permalink
feature(dav/connector): Add createSymlink to Directory node
Browse files Browse the repository at this point in the history
  • Loading branch information
taminob committed Nov 7, 2023
1 parent fbe0e25 commit 301b999
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions apps/dav/lib/Connector/Sabre/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,51 @@ public function createDirectory($name) {
}
}

/**
* Creates a new symlink
*
* @param string $name
* @param string target
*/
public function createSymlink($name, $target) {
try {
if (!$this->info->isCreatable()) {
throw new \Sabre\DAV\Exception\Forbidden();
}

// TODO: check if symlink target leaves data dir
$this->fileView->verifyPath($this->path, $name);

[$storage, $internalPath] = $this->fileView->resolvePath($this->path);
if (!$storage->instanceOfStorage(\OC\Files\Storage\Local::class)) {
throw new \Sabre\DAV\Exception\NotImplemented("Symlinks currently not supported on non-local storages - failed to create '$name'!");
}

$internalPath = $internalPath . '/' . $name;
$storage->unlink($internalPath);
if (!$storage->symlink($target, $internalPath)) {
throw new \Sabre\DAV\Exception\Forbidden("Could not create symlink '$name'!");
}
$storage->getUpdater()->update($internalPath);
$newEtag = $storage->getETag($internalPath);
$infoData = [
'type' => FileInfo::TYPE_FILE,
'etag' => $newEtag,
];
$path = \OC\Files\Filesystem::normalizePath($this->path . '/' . $name);
$this->fileView->putFileInfo($path, $infoData);
return '"' . $newEtag . '"';
} catch (\OCP\Files\StorageNotAvailableException $e) {
throw new ServiceUnavailable($e->getMessage(), $e->getCode(), $e);
} catch (InvalidPathException $ex) {
throw new InvalidPath($ex->getMessage(), false, $ex);
} catch (ForbiddenException $ex) {
throw new Forbidden($ex->getMessage(), $ex->getRetry(), $ex);
} catch (LockedException $e) {
throw new FileLocked($e->getMessage(), $e->getCode(), $e);
}
}

/**
* Returns a specific child node, referenced by its name
*
Expand Down

0 comments on commit 301b999

Please sign in to comment.