Skip to content

Commit cad0ea3

Browse files
committed
fix: add INodeByPath to Directory [wip]
Signed-off-by: Salvatore Martire <[email protected]>
1 parent b38c07c commit cad0ea3

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

apps/dav/lib/Connector/Sabre/Directory.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
use Sabre\DAV\Exception\ServiceUnavailable;
3939
use Sabre\DAV\IFile;
4040
use Sabre\DAV\INode;
41+
use Sabre\DAV\INodeByPath;
4142

42-
class Directory extends Node implements \Sabre\DAV\ICollection, \Sabre\DAV\IQuota, \Sabre\DAV\IMoveTarget, \Sabre\DAV\ICopyTarget {
43+
class Directory extends Node implements \Sabre\DAV\ICollection,
44+
\Sabre\DAV\IQuota, \Sabre\DAV\IMoveTarget, \Sabre\DAV\ICopyTarget, INodeByPath {
4345
/**
4446
* Cached directory content
4547
* @var FileInfo[]
@@ -490,4 +492,37 @@ public function copyInto($targetName, $sourcePath, INode $sourceNode) {
490492
public function getNode(): Folder {
491493
return $this->node;
492494
}
495+
496+
public function getNodeForPath($path) {
497+
try {
498+
[$destinationDir, $destinationName] = \Sabre\Uri\split($path);
499+
$this->fileView->verifyPath($destinationDir, $destinationName, true);
500+
$info = $this->fileView->getFileInfo($path);
501+
} catch (StorageNotAvailableException $e) {
502+
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage(), 0, $e);
503+
} catch (InvalidPathException $ex) {
504+
throw new InvalidPath($ex->getMessage(), false, $ex);
505+
} catch (ForbiddenException $e) {
506+
throw new \Sabre\DAV\Exception\Forbidden($e->getMessage(), $e->getCode(), $e);
507+
}
508+
509+
if (!$info) {
510+
throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located');
511+
}
512+
513+
if ($info->getMimeType() === FileInfo::MIMETYPE_FOLDER) {
514+
$node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this->tree, $this->shareManager);
515+
} else {
516+
// In case reading a directory was allowed but it turns out the node was a not a directory, reject it now.
517+
if (!$this->info->isReadable()) {
518+
throw new NotFound();
519+
}
520+
521+
$node = new File($this->fileView, $info, $this->shareManager);
522+
}
523+
if ($this->tree) {
524+
$this->tree->cacheNode($node);
525+
}
526+
return $node;
527+
}
493528
}

0 commit comments

Comments
 (0)