diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index 3ec0fa5d12554..6230174984c39 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -26,7 +26,7 @@ class Manager implements IMountManager { private ?array $mountKeys = null; /** @var CappedMemoryCache */ private CappedMemoryCache $pathCache; - /** @var CappedMemoryCache */ + /** @var CappedMemoryCache> */ private CappedMemoryCache $inPathCache; private SetupManager $setupManager; @@ -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); diff --git a/lib/private/Files/Node/LazyFolder.php b/lib/private/Files/Node/LazyFolder.php index cd67de7c33a97..1d441d8980aa3 100644 --- a/lib/private/Files/Node/LazyFolder.php +++ b/lib/private/Files/Node/LazyFolder.php @@ -109,7 +109,7 @@ public function getMount(string $mountPoint): IMountPoint { } /** - * @return IMountPoint[] + * @return list */ public function getMountsIn(string $mountPoint): array { return $this->__call(__FUNCTION__, func_get_args()); diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 095db425ed606..74e24664a5c99 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -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); diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php index cca0b6784a211..6ae6e4ed547bd 100644 --- a/lib/private/Files/Utils/Scanner.php +++ b/lib/private/Files/Utils/Scanner.php @@ -54,12 +54,11 @@ public function __construct( } /** - * get all storages for $dir + * Get all storages for a specific directory. * - * @param string $dir * @return array */ - protected function getMounts($dir) { + protected function getMounts(string $dir): array { //TODO: move to the node based fileapi once that's done $this->setupManager->tearDown(); @@ -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 { @@ -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 { @@ -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()); } } diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index da3900bff4a66..5d78ee627cd5c 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -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(); diff --git a/lib/public/Files/IRootFolder.php b/lib/public/Files/IRootFolder.php index fb8532f8c8153..cd3b1c16cdf61 100644 --- a/lib/public/Files/IRootFolder.php +++ b/lib/public/Files/IRootFolder.php @@ -61,7 +61,7 @@ public function getByIdInPath(int $id, string $path); public function getFirstNodeByIdInPath(int $id, string $path): ?Node; /** - * @return IMountPoint[] + * @return list * * @since 28.0.0 */ diff --git a/lib/public/Files/Mount/IMountManager.php b/lib/public/Files/Mount/IMountManager.php index 43a771c07ce82..f174011efc124 100644 --- a/lib/public/Files/Mount/IMountManager.php +++ b/lib/public/Files/Mount/IMountManager.php @@ -55,7 +55,7 @@ public function find(string $path): ?IMountPoint; * Find all mounts in $path * * @param string $path - * @return IMountPoint[] + * @return list Returns a sorted list of mount point * @since 8.2.0 */ public function findIn(string $path): array; diff --git a/tests/lib/Files/Utils/ScannerTest.php b/tests/lib/Files/Utils/ScannerTest.php index 044c7ac0ca8dc..435e7b38ee908 100644 --- a/tests/lib/Files/Utils/ScannerTest.php +++ b/tests/lib/Files/Utils/ScannerTest.php @@ -1,5 +1,7 @@ mounts[] = $mount; + /** @var array $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(); } @@ -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'); @@ -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'));