|
16 | 16 | use OCP\Files\Config\IMountProvider; |
17 | 17 | use OCP\Files\Config\IMountProviderCollection; |
18 | 18 | use OCP\Files\Storage\IStorageFactory; |
| 19 | +use OCP\Files\StorageInvalidException; |
| 20 | +use OCP\Files\StorageNotAvailableException; |
19 | 21 | use OCP\IDBConnection; |
20 | 22 | use OCP\IUser; |
21 | 23 | use OCP\IUserManager; |
@@ -223,4 +225,45 @@ public function testShallow(): void { |
223 | 225 | $this->assertTrue($cache->inCache('folder/bar.txt')); |
224 | 226 | $this->assertFalse($cache->inCache('folder/subfolder/foobar.txt')); |
225 | 227 | } |
| 228 | + |
| 229 | + public function testScanContinuesAfterInvalidStorage(): void { |
| 230 | + $invalidStorage = new class([]) extends Temporary { |
| 231 | + #[\Override] |
| 232 | + public function getMetaData(string $path): ?array { |
| 233 | + throw new StorageInvalidException('Remote share not found'); |
| 234 | + } |
| 235 | + }; |
| 236 | + $storage = new Temporary([]); |
| 237 | + $storage->file_put_contents('foo.txt', 'qwerty'); |
| 238 | + |
| 239 | + $logger = $this->createMock(LoggerInterface::class); |
| 240 | + $logger->expects($this->once()) |
| 241 | + ->method('error') |
| 242 | + ->with( |
| 243 | + 'Storage ' . $invalidStorage->getId() . ' not available', |
| 244 | + $this->callback(fn (array $context): bool => $context['exception'] instanceof StorageInvalidException), |
| 245 | + ); |
| 246 | + |
| 247 | + $scanner = new TestScanner( |
| 248 | + Server::get(IUserManager::class)->get(''), |
| 249 | + Server::get(IDBConnection::class), |
| 250 | + $this->createMock(IEventDispatcher::class), |
| 251 | + $logger, |
| 252 | + Server::get(SetupManager::class), |
| 253 | + ); |
| 254 | + $scanner->addMount(new MountPoint($invalidStorage, '/invalid')); |
| 255 | + $scanner->addMount(new MountPoint($storage, '/valid')); |
| 256 | + |
| 257 | + $emitted = []; |
| 258 | + $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException|StorageInvalidException $e) use (&$emitted): void { |
| 259 | + $emitted[] = $e; |
| 260 | + }); |
| 261 | + |
| 262 | + $scanner->scan(''); |
| 263 | + |
| 264 | + $this->assertCount(1, $emitted); |
| 265 | + $this->assertInstanceOf(StorageInvalidException::class, $emitted[0]); |
| 266 | + $this->assertSame('Remote share not found', $emitted[0]->getMessage()); |
| 267 | + $this->assertTrue($storage->getCache()->inCache('foo.txt')); |
| 268 | + } |
226 | 269 | } |
0 commit comments