Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3781,17 +3781,12 @@
<code><![CDATA[$this->mountManager->findByNumericId($numericId)]]></code>
<code><![CDATA[$this->mountManager->findByStorageId($storageId)]]></code>
<code><![CDATA[$this->mountManager->findIn($mountPoint)]]></code>
<code><![CDATA[$this->user]]></code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType>
<code><![CDATA[MountPoint[]]]></code>
<code><![CDATA[\OC\Files\Mount\MountPoint[]]]></code>
<code><![CDATA[\OC\Files\Mount\MountPoint[]]]></code>
<code><![CDATA[\OC\User\User]]></code>
</MoreSpecificReturnType>
<NullableReturnStatement>
<code><![CDATA[$this->user]]></code>
</NullableReturnStatement>
<UndefinedMethod>
<code><![CDATA[remove]]></code>
</UndefinedMethod>
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Mount/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ public function getSetupManager(): SetupManager {
}

/**
* Return all mounts in a path from a specific mount provider
* Return all mounts in a path from a specific mount provider, indexed by mount point
*
* @param string $path
* @param string[] $mountProviders
* @return IMountPoint[]
* @return array<string, IMountPoint>
*/
public function getMountsByMountProvider(string $path, array $mountProviders) {
$this->getSetupManager()->setupForProvider($path, $mountProviders);
Expand Down
36 changes: 26 additions & 10 deletions lib/private/Files/Node/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OC\Files\Node;

use OC\Files\FileInfo;
Expand All @@ -19,6 +20,8 @@
use OCP\Cache\CappedMemoryCache;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Config\ICachedMountFileInfo;
use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Events\Node\FilesystemTornDownEvent;
use OCP\Files\IRootFolder;
Expand Down Expand Up @@ -82,10 +85,8 @@ public function __construct(

/**
* Get the user for which the filesystem is setup
*
* @return \OC\User\User
*/
public function getUser() {
public function getUser(): ?IUser {
return $this->user;
}

Expand Down Expand Up @@ -411,12 +412,12 @@ public function getByIdInPath(int $id, string $path): array {
} else {
$user = null;
}
$mountsContainingFile = $mountCache->getMountsForFileId($id, $user);
$mountInfosContainingFiles = $mountCache->getMountsForFileId($id, $user);

// if the mount isn't in the cache yet, perform a setup first, then try again
if (count($mountsContainingFile) === 0) {
if (count($mountInfosContainingFiles) === 0) {
$setupManager->setupForPath($path, true);
$mountsContainingFile = $mountCache->getMountsForFileId($id, $user);
$mountInfosContainingFiles = $mountCache->getMountsForFileId($id, $user);
}

// when a user has access through the same storage through multiple paths
Expand All @@ -428,16 +429,31 @@ public function getByIdInPath(int $id, string $path): array {

$mountRootIds = array_map(function ($mount) {
return $mount->getRootId();
}, $mountsContainingFile);
}, $mountInfosContainingFiles);
$mountRootPaths = array_map(function ($mount) {
return $mount->getRootInternalPath();
}, $mountsContainingFile);
}, $mountInfosContainingFiles);
$mountProviders = array_unique(array_map(function ($mount) {
return $mount->getMountProvider();
}, $mountsContainingFile));
}, $mountInfosContainingFiles));
$mountPoints = array_map(fn (ICachedMountInfo $mountInfo) => $mountInfo->getMountPoint(), $mountInfosContainingFiles);
$mountRoots = array_combine($mountRootIds, $mountRootPaths);

$mountsContainingFile = array_filter(array_map($this->mountManager->getMountFromMountInfo(...), $mountsContainingFile));
$mounts = $this->mountManager->getMountsByMountProvider($path, $mountProviders);
$mountsContainingFile = array_filter($mounts, fn (IMountPoint $mount) => in_array($mount->getMountPoint(), $mountPoints));

if (count($mountsContainingFile) == 0 && count($mountInfosContainingFiles) > 0) {
if (!$user) {
$user = $this->getUser()?->getUID();
}
if (!$user) {
/** @var ICachedMountFileInfo $firstMount */
$firstMount = current($mountInfosContainingFiles);
$user = $firstMount->getUser()->getUID();
}
$mountInfosContainingFiles = array_filter($mountInfosContainingFiles, fn (ICachedMountInfo $mountInfo) => $mountInfo->getUser()->getUID() === $user);
$mountsContainingFile = array_filter(array_map($this->mountManager->getMountFromMountInfo(...), $mountInfosContainingFiles));
}

if (count($mountsContainingFile) === 0) {
if ($user === $this->getAppDataDirectoryName()) {
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/Files/Node/FolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ public function testGetById(): void {

$manager->method('getMountFromMountInfo')
->willReturn($mount);
$manager->method('getMountsByMountProvider')
->willReturn([$mount]);

$node = new Folder($root, $view, '/bar/foo');
$result = $node->getById(1);
Expand Down Expand Up @@ -586,6 +588,8 @@ public function testGetByIdMountRoot(): void {

$manager->method('getMountFromMountInfo')
->willReturn($mount);
$manager->method('getMountsByMountProvider')
->willReturn([$mount]);

$node = new Folder($root, $view, '/bar');
$result = $node->getById(1);
Expand Down Expand Up @@ -631,6 +635,8 @@ public function testGetByIdOutsideFolder(): void {

$manager->method('getMountFromMountInfo')
->willReturn($mount);
$manager->method('getMountsByMountProvider')
->willReturn([$mount]);

$node = new Folder($root, $view, '/bar/foo');
$result = $node->getById(1);
Expand Down Expand Up @@ -694,6 +700,8 @@ public function testGetByIdMultipleStorages(): void {
}
return null;
});
$manager->method('getMountsByMountProvider')
->willReturn([$mount1, $mount2]);

$node = new Folder($root, $view, '/bar/foo');
$result = $node->getById(1);
Expand Down
Loading