}
/**
- * @return array{array<string, ICache>, array<string, IMountPoint>}
+ * @return list{0?: array<array-key, ICache>, 1?: array<array-key, IMountPoint>}
*/
public function getCachesAndMountPointsForSearch(IRootFolder $root, string $path, bool $limitToHome = false): array {
$rootLength = strlen($path);
- $mount = $root->getMount($path);
- $storage = $mount->getStorage();
+ $storage = null;
+ if (method_exists($root, 'getMount')) {
+ /** @var IMountPoint $mount */
+ $mount = $root->getMount($path);
+ $storage = $mount->getStorage();
+ }
+ if ($storage === null) {
+ return [];
+ }
$internalPath = $mount->getInternalPath($path);
if ($internalPath !== '') {
// a temporary CacheJail is used to handle filtering down the results to within this folder
+ /** @var ICache[] $caches */
$caches = ['' => new CacheJail($storage->getCache(''), $internalPath)];
} else {
+ /** @var ICache[] $caches */
$caches = ['' => $storage->getCache('')];
}
+ /** @var IMountPoint[] $mountByMountPoint */
$mountByMountPoint = ['' => $mount];
- if (!$limitToHome) {
+ if (!$limitToHome && method_exists($root, 'getMountsIn')) {
/** @var IMountPoint[] $mounts */
$mounts = $root->getMountsIn($path);
foreach ($mounts as $mount) {
return $this->path;
}
- /**
- * @return \OCP\Files\Storage
- */
public function getStorage() {
return $this->storage;
}
* @return array
*/
protected function getByIdInRootMount(int $id): array {
- $mount = $this->root->getMount('');
- $cacheEntry = $mount->getStorage()->getCache($this->path)->get($id);
+ $storage = null;
+ if (\method_exists($this->root, 'getMount')) {
+ /** @var IMountPoint $mount */
+ $mount = $this->root->getMount('');
+ $storage = $mount->getStorage();
+ }
+ $cacheEntry = $storage?->getCache($this->path)->get($id);
if (!$cacheEntry) {
return [];
}
return [$this->root->createNode(
$absolutePath, new \OC\Files\FileInfo(
$absolutePath,
- $mount->getStorage(),
+ $storage,
$cacheEntry->getPath(),
$cacheEntry,
$mount
use OCP\Files\FileInfo;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
+use OCP\Files\Node as INode;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Lock\LockedException;
use Symfony\Component\EventDispatcher\GenericEvent;
// FIXME: this class really should be abstract
-class Node implements \OCP\Files\Node {
+class Node implements INode {
/**
* @var \OC\Files\View $view
*/
$args = !empty($args) ? $args : [$this];
$dispatcher = \OC::$server->getEventDispatcher();
foreach ($hooks as $hook) {
- $this->root->emit('\OC\Files', $hook, $args);
+ if (method_exists($this->root, 'emit')) {
+ $this->root->emit('\OC\Files', $hook, $args);
+ }
$dispatcher->dispatch('\OCP\Files::' . $hook, new GenericEvent($args));
}
}
return $this->getFileInfo(false)->isCreatable();
}
- /**
- * @return Node
- */
- public function getParent() {
+ public function getParent(): INode|IRootFolder {
if ($this->parent === null) {
$newPath = dirname($this->path);
if ($newPath === '' || $newPath === '.' || $newPath === '/') {
/**
* @param string $targetPath
- * @return \OCP\Files\Node
+ * @return INode
* @throws InvalidPathException
* @throws NotFoundException
* @throws NotPermittedException if copy not allowed or failed
/**
* @param string $targetPath
- * @return \OCP\Files\Node
+ * @return INode
* @throws InvalidPathException
* @throws NotFoundException
* @throws NotPermittedException if move not allowed or failed
use OCP\Files\Events\Node\FilesystemTornDownEvent;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
+use OCP\Files\Node as INode;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IUser;
}
/**
- * @return Node
* @throws \OCP\Files\NotFoundException
*/
- public function getParent() {
+ public function getParent(): INode|IRootFolder {
throw new NotFoundException();
}
use OC\Files\Storage\Temporary;
use OC\Files\Storage\Wrapper\Jail;
use OCP\Files\Cache\ICacheEntry;
+use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
use OCP\Files\Search\ISearchComparison;
}
public function testIsSubNode() {
- $file = new Node(null, $this->view, '/foo/bar');
- $folder = new Folder(null, $this->view, '/foo');
+ $rootFolderMock = $this->createMock(IRootFolder::class);
+ $file = new Node($rootFolderMock, $this->view, '/foo/bar');
+ $folder = new Folder($rootFolderMock, $this->view, '/foo');
$this->assertTrue($folder->isSubNode($file));
$this->assertFalse($folder->isSubNode($folder));
- $file = new Node(null, $this->view, '/foobar');
+ $file = new Node($rootFolderMock, $this->view, '/foobar');
$this->assertFalse($folder->isSubNode($file));
}