|
38 | 38 | use Sabre\DAV\Exception\ServiceUnavailable; |
39 | 39 | use Sabre\DAV\IFile; |
40 | 40 | use Sabre\DAV\INode; |
| 41 | +use Sabre\DAV\INodeByPath; |
41 | 42 |
|
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 { |
43 | 45 | /** |
44 | 46 | * Cached directory content |
45 | 47 | * @var FileInfo[] |
@@ -490,4 +492,37 @@ public function copyInto($targetName, $sourcePath, INode $sourceNode) { |
490 | 492 | public function getNode(): Folder { |
491 | 493 | return $this->node; |
492 | 494 | } |
| 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 | + } |
493 | 528 | } |
0 commit comments