Skip to content
Open
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
7 changes: 1 addition & 6 deletions lib/private/Files/Mount/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Manager implements IMountManager {
private ?array $mountKeys = null;
/** @var CappedMemoryCache<IMountPoint> */
private CappedMemoryCache $pathCache;
/** @var CappedMemoryCache<IMountPoint[]> */
/** @var CappedMemoryCache<list<IMountPoint>> */
private CappedMemoryCache $inPathCache;
private SetupManager $setupManager;

Expand Down Expand Up @@ -110,11 +110,6 @@ public function find(string $path): IMountPoint {
throw new NotFoundException('No mount for path ' . $path . ' existing mounts (' . count($this->mounts) . '): ' . implode(',', array_keys($this->mounts)));
}

/**
* Find all mounts in $path
*
* @return IMountPoint[]
*/
#[\Override]
public function findIn(string $path): array {
$this->setupManager->setupForPath($path, true);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Node/LazyFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getMount(string $mountPoint): IMountPoint {
}

/**
* @return IMountPoint[]
* @return list<IMountPoint>
*/
public function getMountsIn(string $mountPoint): array {
return $this->__call(__FUNCTION__, func_get_args());
Expand Down
4 changes: 0 additions & 4 deletions lib/private/Files/Node/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ public function getMount(string $mountPoint): IMountPoint {
return $this->mountManager->find($mountPoint);
}

/**
* @param string $mountPoint
* @return IMountPoint[]
*/
#[\Override]
public function getMountsIn(string $mountPoint): array {
return $this->mountManager->findIn($mountPoint);
Expand Down
11 changes: 5 additions & 6 deletions lib/private/Files/Utils/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ public function __construct(
}

/**
* get all storages for $dir
* Get all storages for a specific directory.
*
* @param string $dir
* @return array<string, IMountPoint>
*/
protected function getMounts($dir) {
protected function getMounts(string $dir): array {
//TODO: move to the node based fileapi once that's done
$this->setupManager->tearDown();

Expand All @@ -79,7 +78,7 @@ protected function getMounts($dir) {
/**
* attach listeners to the scanner
*/
protected function attachListener(MountPoint $mount) {
protected function attachListener(IMountPoint $mount): void {
/** @var \OC\Files\Cache\Scanner $scanner */
$scanner = $mount->getStorage()->getScanner();
$scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount): void {
Expand All @@ -103,7 +102,7 @@ protected function attachListener(MountPoint $mount) {
});
}

public function backgroundScan(string $dir) {
public function backgroundScan(string $dir): void {
$mounts = $this->getMounts($dir);
foreach ($mounts as $mount) {
try {
Expand Down Expand Up @@ -244,7 +243,7 @@ public function scan(string $dir = '', $recursive = \OC\Files\Cache\Scanner::SCA
}
}

private function triggerPropagator(IStorage $storage, $internalPath) {
private function triggerPropagator(IStorage $storage, $internalPath): void {
$storage->getPropagator()->propagateChange($internalPath, time());
}
}
4 changes: 0 additions & 4 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -1570,10 +1570,6 @@ public function getDirectoryContent(string $directory, ?string $mimeTypeFilter =
//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
$mounts = Filesystem::getMountManager()->findIn($path);

// make sure nested mounts are sorted after their parent mounts
// otherwise doesn't propagate the etag across storage boundaries correctly
usort($mounts, static fn (IMountPoint $a, IMountPoint $b): int => $a->getMountPoint() <=> $b->getMountPoint());

$dirLength = strlen($path);
foreach ($mounts as $mount) {
$mountPoint = $mount->getMountPoint();
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Files/IRootFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getByIdInPath(int $id, string $path);
public function getFirstNodeByIdInPath(int $id, string $path): ?Node;

/**
* @return IMountPoint[]
* @return list<IMountPoint>
*
* @since 28.0.0
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Files/Mount/IMountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function find(string $path): ?IMountPoint;
* Find all mounts in $path
*
* @param string $path
* @return IMountPoint[]
* @return list<IMountPoint> Returns a sorted list of mount point
* @since 8.2.0
*/
public function findIn(string $path): array;
Expand Down
67 changes: 24 additions & 43 deletions tests/lib/Files/Utils/ScannerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand All @@ -21,45 +23,35 @@
use OCP\IUser;
use OCP\IUserManager;
use OCP\Server;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use Psr\Log\LoggerInterface;
use Test\TestCase;
use Test\Util\User\Dummy;

class TestScanner extends Scanner {
/**
* @var MountPoint[] $mounts
*/
private $mounts = [];

/**
* @param MountPoint $mount
*/
public function addMount($mount) {
$this->mounts[] = $mount;
/** @var array<string, MountPoint> $mounts */
private array $mounts = [];

public function addMount(MountPoint $mount): void {
$this->mounts[$mount->getMountPoint()] = $mount;
}

#[\Override]
protected function getMounts($dir) {
protected function getMounts(string $dir): array {
return $this->mounts;
}
}

/**
* Class ScannerTest
*
*
* @package Test\Files\Utils
*/
#[\PHPUnit\Framework\Attributes\Group('DB')]
class ScannerTest extends \Test\TestCase {
/**
* @var \Test\Util\User\Dummy
*/
private $userBackend;
#[Group('DB')]
class ScannerTest extends TestCase {
private Dummy $userBackend;

#[\Override]
protected function setUp(): void {
parent::setUp();

$this->userBackend = new \Test\Util\User\Dummy();
$this->userBackend = new Dummy();
Server::get(IUserManager::class)->registerBackend($this->userBackend);
$this->loginAsUser();
}
Expand Down Expand Up @@ -166,25 +158,14 @@ public function testScanSubMount(): void {
$this->assertTrue($cache->inCache('folder/bar.txt'));
}

public static function invalidPathProvider(): array {
return [
[
'../',
],
[
'..\\',
],
[
'../..\\../',
],
];
public static function invalidPathProvider(): \Generator {
yield [ '../' ];
yield [ '..\\' ];
yield [ '../..\\../' ];
}

/**
* @param string $invalidPath
*/
#[\PHPUnit\Framework\Attributes\DataProvider('invalidPathProvider')]
public function testInvalidPathScanning($invalidPath): void {
#[DataProvider(methodName: 'invalidPathProvider')]
public function testInvalidPathScanning(string $invalidPath): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid path to scan');

Expand Down Expand Up @@ -249,14 +230,14 @@ public function testShallow(): void {
);
$scanner->addMount($mount);

$scanner->scan('', $recusive = false);
$scanner->scan('', false);
$this->assertTrue($cache->inCache('folder'));
$this->assertFalse($cache->inCache('folder/subfolder'));
$this->assertTrue($cache->inCache('foo.txt'));
$this->assertFalse($cache->inCache('folder/bar.txt'));
$this->assertFalse($cache->inCache('folder/subfolder/foobar.txt'));

$scanner->scan('folder', $recusive = false);
$scanner->scan('folder', false);
$this->assertTrue($cache->inCache('folder'));
$this->assertTrue($cache->inCache('folder/subfolder'));
$this->assertTrue($cache->inCache('foo.txt'));
Expand Down
Loading