summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2023-07-04 22:07:29 +0200
committerGitHub <noreply@github.com>2023-07-04 22:07:29 +0200
commitdd2dfc89fd34b1c7c3f38e33b5942f2a57fafc7a (patch)
treebc04b9fab6282a3c47aac2cb76eaee71c8eca112 /lib
parentbab5a54aed49107c96ebfc783e52fda6e02b0e7a (diff)
parent5ba5c2d88e51f94138e27e3eb2c4a4b83d62bb1f (diff)
downloadnextcloud-server-dd2dfc89fd34b1c7c3f38e33b5942f2a57fafc7a.tar.gz
nextcloud-server-dd2dfc89fd34b1c7c3f38e33b5942f2a57fafc7a.zip
Merge pull request #38976 from nextcloud/backport/38625/stable27
[stable27] fix: expect interface, not a specific implementation
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Cache/QuerySearchHelper.php14
-rw-r--r--lib/private/Files/FileInfo.php3
-rw-r--r--lib/private/Files/Node/Folder.php21
-rw-r--r--lib/private/Files/Node/LazyFolder.php7
-rw-r--r--lib/private/Files/Node/Node.php24
-rw-r--r--lib/private/Files/Node/Root.php12
-rw-r--r--lib/public/Files/IRootFolder.php13
7 files changed, 53 insertions, 41 deletions
diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php
index 30b3c7225ac..75e203d5fd9 100644
--- a/lib/private/Files/Cache/QuerySearchHelper.php
+++ b/lib/private/Files/Cache/QuerySearchHelper.php
@@ -26,15 +26,14 @@
namespace OC\Files\Cache;
use OC\Files\Cache\Wrapper\CacheJail;
-use OC\Files\Node\Root;
use OC\Files\Search\QueryOptimizer\QueryOptimizer;
use OC\Files\Search\SearchBinaryOperator;
use OC\SystemConfig;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\ICacheEntry;
-use OCP\Files\Folder;
use OCP\Files\IMimeTypeLoader;
+use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchQuery;
@@ -196,24 +195,29 @@ class QuerySearchHelper {
}
/**
- * @return array{array<string, ICache>, array<string, IMountPoint>}
+ * @return list{0?: array<array-key, ICache>, 1?: array<array-key, IMountPoint>}
*/
- public function getCachesAndMountPointsForSearch(Root $root, string $path, bool $limitToHome = false): array {
+ public function getCachesAndMountPointsForSearch(IRootFolder $root, string $path, bool $limitToHome = false): array {
$rootLength = strlen($path);
$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) {
- /** @var IMountPoint[] $mounts */
$mounts = $root->getMountsIn($path);
foreach ($mounts as $mount) {
$storage = $mount->getStorage();
diff --git a/lib/private/Files/FileInfo.php b/lib/private/Files/FileInfo.php
index d9b773cc2a6..2b6b83a2546 100644
--- a/lib/private/Files/FileInfo.php
+++ b/lib/private/Files/FileInfo.php
@@ -143,9 +143,6 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
return $this->path;
}
- /**
- * @return \OCP\Files\Storage
- */
public function getStorage() {
return $this->storage;
}
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php
index 1d6d88bafe6..38a7645631c 100644
--- a/lib/private/Files/Node/Folder.php
+++ b/lib/private/Files/Node/Folder.php
@@ -40,6 +40,7 @@ use OC\Files\Utils\PathHelper;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\FileInfo;
use OCP\Files\Mount\IMountPoint;
+use OCP\Files\Node as INode;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\Search\ISearchBinaryOperator;
@@ -109,12 +110,7 @@ class Folder extends Node implements \OCP\Files\Folder {
}, $folderContent);
}
- /**
- * @param string $path
- * @param FileInfo $info
- * @return File|Folder
- */
- protected function createNode($path, FileInfo $info = null, bool $infoHasSubMountsIncluded = true) {
+ protected function createNode(string $path, ?FileInfo $info = null, bool $infoHasSubMountsIncluded = true): INode {
if (is_null($info)) {
$isDir = $this->view->is_dir($path);
} else {
@@ -330,8 +326,15 @@ class Folder extends Node implements \OCP\Files\Folder {
* @return array
*/
protected function getByIdInRootMount(int $id): array {
+ if (!method_exists($this->root, 'createNode')) {
+ // Always expected to be false. Being a method of Folder, this is
+ // always implemented. For it is an internal method and should not
+ // be exposed and made public, it is not part of an interface.
+ return [];
+ }
$mount = $this->root->getMount('');
- $cacheEntry = $mount->getStorage()->getCache($this->path)->get($id);
+ $storage = $mount->getStorage();
+ $cacheEntry = $storage?->getCache($this->path)->get($id);
if (!$cacheEntry) {
return [];
}
@@ -346,7 +349,7 @@ class Folder extends Node implements \OCP\Files\Folder {
return [$this->root->createNode(
$absolutePath, new \OC\Files\FileInfo(
$absolutePath,
- $mount->getStorage(),
+ $storage,
$cacheEntry->getPath(),
$cacheEntry,
$mount
@@ -384,7 +387,7 @@ class Folder extends Node implements \OCP\Files\Folder {
/**
* @param int $limit
* @param int $offset
- * @return \OCP\Files\Node[]
+ * @return INode[]
*/
public function getRecent($limit, $offset = 0) {
$filterOutNonEmptyFolder = new SearchBinaryOperator(
diff --git a/lib/private/Files/Node/LazyFolder.php b/lib/private/Files/Node/LazyFolder.php
index c843baabade..9f9528f69bd 100644
--- a/lib/private/Files/Node/LazyFolder.php
+++ b/lib/private/Files/Node/LazyFolder.php
@@ -29,6 +29,7 @@ namespace OC\Files\Node;
use OC\Files\Utils\PathHelper;
use OCP\Files\Folder;
use OCP\Constants;
+use OCP\Files\Mount\IMountPoint;
/**
* Class LazyFolder
@@ -111,14 +112,14 @@ class LazyFolder implements Folder {
/**
* @inheritDoc
*/
- public function getMount($mountPoint) {
+ public function getMount(string $mountPoint): IMountPoint {
return $this->__call(__FUNCTION__, func_get_args());
}
/**
- * @inheritDoc
+ * @return IMountPoint[]
*/
- public function getMountsIn($mountPoint) {
+ public function getMountsIn(string $mountPoint): array {
return $this->__call(__FUNCTION__, func_get_args());
}
diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php
index 0eef2716141..4ba2c472c67 100644
--- a/lib/private/Files/Node/Node.php
+++ b/lib/private/Files/Node/Node.php
@@ -34,6 +34,8 @@ use OC\Files\Mount\MoveableMount;
use OC\Files\Utils\PathHelper;
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;
@@ -41,16 +43,13 @@ use OCP\PreConditionNotMetException;
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
*/
protected $view;
- /**
- * @var \OC\Files\Node\Root $root
- */
- protected $root;
+ protected IRootFolder $root;
/**
* @var string $path Absolute path to the node (e.g. /admin/files/folder/file)
@@ -72,7 +71,7 @@ class Node implements \OCP\Files\Node {
* @param string $path
* @param FileInfo $fileInfo
*/
- public function __construct($root, $view, $path, $fileInfo = null, ?Node $parent = null, bool $infoHasSubMountsIncluded = true) {
+ public function __construct(IRootFolder $root, $view, $path, $fileInfo = null, ?Node $parent = null, bool $infoHasSubMountsIncluded = true) {
if (Filesystem::normalizePath($view->getRoot()) !== '/') {
throw new PreConditionNotMetException('The view passed to the node should not have any fake root set');
}
@@ -130,7 +129,9 @@ class Node implements \OCP\Files\Node {
$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));
}
}
@@ -290,10 +291,7 @@ class Node implements \OCP\Files\Node {
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 === '/') {
@@ -402,7 +400,7 @@ class Node implements \OCP\Files\Node {
/**
* @param string $targetPath
- * @return \OC\Files\Node\Node
+ * @return INode
* @throws InvalidPathException
* @throws NotFoundException
* @throws NotPermittedException if copy not allowed or failed
@@ -428,7 +426,7 @@ class Node implements \OCP\Files\Node {
/**
* @param string $targetPath
- * @return \OC\Files\Node\Node
+ * @return INode
* @throws InvalidPathException
* @throws NotFoundException
* @throws NotPermittedException if move not allowed or failed
diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php
index e9fb14e5364..7bd88981ff2 100644
--- a/lib/private/Files/Node/Root.php
+++ b/lib/private/Files/Node/Root.php
@@ -45,6 +45,7 @@ use OCP\Files\Config\IUserMountCache;
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;
@@ -153,11 +154,7 @@ class Root extends Folder implements IRootFolder {
$this->mountManager->addMount($mount);
}
- /**
- * @param string $mountPoint
- * @return \OC\Files\Mount\MountPoint
- */
- public function getMount($mountPoint) {
+ public function getMount(string $mountPoint): IMountPoint {
return $this->mountManager->find($mountPoint);
}
@@ -165,7 +162,7 @@ class Root extends Folder implements IRootFolder {
* @param string $mountPoint
* @return \OC\Files\Mount\MountPoint[]
*/
- public function getMountsIn($mountPoint) {
+ public function getMountsIn(string $mountPoint): array {
return $this->mountManager->findIn($mountPoint);
}
@@ -339,10 +336,9 @@ class Root extends Folder implements IRootFolder {
}
/**
- * @return Node
* @throws \OCP\Files\NotFoundException
*/
- public function getParent() {
+ public function getParent(): INode|IRootFolder {
throw new NotFoundException();
}
diff --git a/lib/public/Files/IRootFolder.php b/lib/public/Files/IRootFolder.php
index 452c0fd3157..49d41ab998c 100644
--- a/lib/public/Files/IRootFolder.php
+++ b/lib/public/Files/IRootFolder.php
@@ -26,6 +26,7 @@ namespace OCP\Files;
use OC\Hooks\Emitter;
use OC\User\NoUserException;
+use OCP\Files\Mount\IMountPoint;
/**
* Interface IRootFolder
@@ -55,4 +56,16 @@ interface IRootFolder extends Folder, Emitter {
* @since 24.0.0
*/
public function getByIdInPath(int $id, string $path);
+
+ /**
+ * @return IMountPoint[]
+ *
+ * @since 27.0.1
+ */
+ public function getMountsIn(string $mountPoint): array;
+
+ /**
+ * @since 27.0.1
+ */
+ public function getMount(string $mountPoint): IMountPoint;
}