Skip to content

Commit

Permalink
chore: ugly type juggling
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Jun 8, 2023
1 parent 5085eac commit 1acc054
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
16 changes: 12 additions & 4 deletions lib/private/Files/Cache/QuerySearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,23 +195,31 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array
}

/**
* @return array{array<string, ICache>, array<string, IMountPoint>}
* @return array{0?: array<string, ICache>, 1?: array<string, IMountPoint>}
*/
public function getCachesAndMountPointsForSearch(IRootFolder $root, string $path, bool $limitToHome = false): array {
$rootLength = strlen($path);
$mount = $root->getMount($path);
$storage = $mount->getStorage();
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('')];
}
$mountByMountPoint = ['' => $mount];

if (!$limitToHome) {
if (!$limitToHome && method_exists($root, 'getMountsIn')) {
/** @var IMountPoint[] $mounts */
$mounts = $root->getMountsIn($path);
foreach ($mounts as $mount) {
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorage;
use OCP\IUser;

class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
Expand Down Expand Up @@ -79,7 +80,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {

/**
* @param string|boolean $path
* @param Storage\Storage $storage
* @param Storage\Storage|IStorage $storage
* @param string $internalPath
* @param array|ICacheEntry $data
* @param IMountPoint $mount
Expand Down
11 changes: 8 additions & 3 deletions lib/private/Files/Node/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,13 @@ protected function getAppDataDirectoryName(): string {
* @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 [];
}
Expand All @@ -346,7 +351,7 @@ protected function getByIdInRootMount(int $id): array {
return [$this->root->createNode(
$absolutePath, new \OC\Files\FileInfo(
$absolutePath,
$mount->getStorage(),
$storage,
$cacheEntry->getPath(),
$cacheEntry,
$mount
Expand Down
6 changes: 4 additions & 2 deletions lib/private/Files/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ protected function sendHooks($hooks, array $args = null) {
$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));
}
}
Expand Down Expand Up @@ -289,7 +291,7 @@ public function isCreatable() {
}

/**
* @return Node
* @return \OCP\Files\Node
*/
public function getParent() {
if ($this->parent === null) {
Expand Down

0 comments on commit 1acc054

Please sign in to comment.