Skip to content

Commit b7c1594

Browse files
committed
chore: Get rid of AppLocator helper
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 3cea218 commit b7c1594

File tree

10 files changed

+41
-106
lines changed

10 files changed

+41
-106
lines changed

core/Command/Integrity/CheckApp.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
66
* SPDX-License-Identifier: AGPL-3.0-only
77
*/
8+
89
namespace OC\Core\Command\Integrity;
910

1011
use OC\Core\Command\Base;
1112
use OC\IntegrityCheck\Checker;
12-
use OC\IntegrityCheck\Helpers\AppLocator;
1313
use OC\IntegrityCheck\Helpers\FileAccessHelper;
1414
use OCP\App\IAppManager;
1515
use Symfony\Component\Console\Input\InputArgument;
@@ -25,7 +25,6 @@
2525
class CheckApp extends Base {
2626
public function __construct(
2727
private Checker $checker,
28-
private AppLocator $appLocator,
2928
private FileAccessHelper $fileAccessHelper,
3029
private IAppManager $appManager,
3130
) {
@@ -70,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7069
foreach ($appIds as $appId) {
7170
$path = (string)$input->getOption('path');
7271
if ($path === '') {
73-
$path = $this->appLocator->getAppPath($appId);
72+
$path = $this->appManager->getAppPath($appId);
7473
}
7574

7675
if ($this->appManager->isShipped($appId) || $this->fileAccessHelper->file_exists($path . '/appinfo/signature.json')) {

lib/private/App/AppManager.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,14 @@ public function loadApps(array $types = []): bool {
252252
foreach ($apps as $app) {
253253
// If the app is already loaded then autoloading it makes no sense
254254
if (!$this->isAppLoaded($app)) {
255-
$path = \OC_App::getAppPath($app);
256-
if ($path !== false) {
255+
try {
256+
$path = $this->getAppPath($app);
257257
\OC_App::registerAutoloading($app, $path);
258+
} catch (AppPathNotFoundException $e) {
259+
$this->logger->info('Error during app loading: ' . $e->getMessage(), [
260+
'exception' => $e,
261+
'app' => $app,
262+
]);
258263
}
259264
}
260265
}
@@ -450,8 +455,13 @@ public function loadApp(string $app): void {
450455
return;
451456
}
452457
$this->loadedApps[$app] = true;
453-
$appPath = \OC_App::getAppPath($app);
454-
if ($appPath === false) {
458+
try {
459+
$appPath = $this->getAppPath($app);
460+
} catch (AppPathNotFoundException $e) {
461+
$this->logger->info('Error during app loading: ' . $e->getMessage(), [
462+
'exception' => $e,
463+
'app' => $app,
464+
]);
455465
return;
456466
}
457467
$eventLogger = \OC::$server->get(IEventLogger::class);

lib/private/DB/MigrationService.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
use Doctrine\DBAL\Schema\Sequence;
1414
use Doctrine\DBAL\Schema\Table;
1515
use OC\App\InfoParser;
16-
use OC\IntegrityCheck\Helpers\AppLocator;
1716
use OC\Migration\SimpleOutput;
17+
use OCP\App\IAppManager;
1818
use OCP\AppFramework\App;
1919
use OCP\AppFramework\QueryException;
2020
use OCP\DB\ISchemaWrapper;
@@ -39,7 +39,12 @@ class MigrationService {
3939
/**
4040
* @throws \Exception
4141
*/
42-
public function __construct(string $appName, Connection $connection, ?IOutput $output = null, ?AppLocator $appLocator = null, ?LoggerInterface $logger = null) {
42+
public function __construct(
43+
string $appName,
44+
Connection $connection,
45+
?IOutput $output = null,
46+
?LoggerInterface $logger = null,
47+
) {
4348
$this->appName = $appName;
4449
$this->connection = $connection;
4550
if ($logger === null) {
@@ -58,10 +63,8 @@ public function __construct(string $appName, Connection $connection, ?IOutput $o
5863
$this->migrationsNamespace = 'OC\\Core\\Migrations';
5964
$this->checkOracle = true;
6065
} else {
61-
if ($appLocator === null) {
62-
$appLocator = new AppLocator();
63-
}
64-
$appPath = $appLocator->getAppPath($appName);
66+
$appManager = Server::get(IAppManager::class);
67+
$appPath = $appManager->getAppPath($appName);
6568
$namespace = App::buildAppNamespace($appName);
6669
$this->migrationsPath = "$appPath/lib/Migration";
6770
$this->migrationsNamespace = $namespace . '\\Migration';
@@ -728,7 +731,7 @@ protected function logErrorOrWarning(string $log): void {
728731
}
729732
}
730733

731-
private function ensureMigrationsAreLoaded() {
734+
private function ensureMigrationsAreLoaded(): void {
732735
if (empty($this->migrations)) {
733736
$this->migrations = $this->findMigrations();
734737
}

lib/private/Installer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use OC\DB\Connection;
1919
use OC\DB\MigrationService;
2020
use OC\Files\FilenameValidator;
21-
use OC_App;
2221
use OCP\App\AppPathNotFoundException;
2322
use OCP\App\IAppManager;
2423
use OCP\BackgroundJob\IJobList;

lib/private/IntegrityCheck/Checker.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use OC\Core\Command\Maintenance\Mimetype\GenerateMimetypeFileBuilder;
1212
use OC\IntegrityCheck\Exceptions\InvalidSignatureException;
13-
use OC\IntegrityCheck\Helpers\AppLocator;
1413
use OC\IntegrityCheck\Helpers\EnvironmentHelper;
1514
use OC\IntegrityCheck\Helpers\FileAccessHelper;
1615
use OC\IntegrityCheck\Iterator\ExcludeFileByNameFilterIterator;
@@ -44,7 +43,6 @@ public function __construct(
4443
private ServerVersion $serverVersion,
4544
private EnvironmentHelper $environmentHelper,
4645
private FileAccessHelper $fileAccessHelper,
47-
private AppLocator $appLocator,
4846
private ?IConfig $config,
4947
private ?IAppConfig $appConfig,
5048
ICacheFactory $cacheFactory,
@@ -460,7 +458,7 @@ private function cleanResults() {
460458
public function verifyAppSignature(string $appId, string $path = '', bool $forceVerify = false): array {
461459
try {
462460
if ($path === '') {
463-
$path = $this->appLocator->getAppPath($appId);
461+
$path = $this->appManager->getAppPath($appId);
464462
}
465463
$result = $this->verify(
466464
$path . '/appinfo/signature.json',
@@ -545,7 +543,7 @@ public function runInstanceVerification() {
545543
$appNeedsToBeChecked = false;
546544
if ($isShipped) {
547545
$appNeedsToBeChecked = true;
548-
} elseif ($this->fileAccessHelper->file_exists($this->appLocator->getAppPath($appId) . '/appinfo/signature.json')) {
546+
} elseif ($this->fileAccessHelper->file_exists($this->appManager->getAppPath($appId) . '/appinfo/signature.json')) {
549547
// Otherwise only if the application explicitly ships a signature.json file
550548
$appNeedsToBeChecked = true;
551549
}

lib/private/IntegrityCheck/Helpers/AppLocator.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

lib/private/Server.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
use OC\Http\Client\ClientService;
6666
use OC\Http\Client\NegativeDnsCache;
6767
use OC\IntegrityCheck\Checker;
68-
use OC\IntegrityCheck\Helpers\AppLocator;
6968
use OC\IntegrityCheck\Helpers\EnvironmentHelper;
7069
use OC\IntegrityCheck\Helpers\FileAccessHelper;
7170
use OC\KnownUser\KnownUserService;
@@ -839,7 +838,6 @@ public function __construct($webRoot, \OC\Config $config) {
839838
$c->get(ServerVersion::class),
840839
$c->get(EnvironmentHelper::class),
841840
new FileAccessHelper(),
842-
new AppLocator(),
843841
$config,
844842
$appConfig,
845843
$c->get(ICacheFactory::class),

tests/lib/DB/MigrationsTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use OC\DB\MigrationService;
2121
use OC\DB\SchemaWrapper;
2222
use OC\Migration\MetadataManager;
23+
use OCP\App\AppPathNotFoundException;
2324
use OCP\App\IAppManager;
2425
use OCP\IDBConnection;
2526
use OCP\Migration\Attributes\AddColumn;
@@ -81,10 +82,10 @@ public function testExecuteUnknownStep(): void {
8182

8283

8384
public function testUnknownApp(): void {
84-
$this->expectException(\Exception::class);
85-
$this->expectExceptionMessage('App not found');
85+
$this->expectException(AppPathNotFoundException::class);
86+
$this->expectExceptionMessage('Could not find path for unknown_bloody_app');
8687

87-
$migrationService = new MigrationService('unknown-bloody-app', $this->db);
88+
$migrationService = new MigrationService('unknown_bloody_app', $this->db);
8889
}
8990

9091

tests/lib/IntegrityCheck/CheckerTest.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use OC\Core\Command\Maintenance\Mimetype\GenerateMimetypeFileBuilder;
1212
use OC\Files\Type\Detection;
1313
use OC\IntegrityCheck\Checker;
14-
use OC\IntegrityCheck\Helpers\AppLocator;
1514
use OC\IntegrityCheck\Helpers\EnvironmentHelper;
1615
use OC\IntegrityCheck\Helpers\FileAccessHelper;
1716
use OC\Memcache\NullCache;
@@ -29,10 +28,6 @@ class CheckerTest extends TestCase {
2928
private $serverVersion;
3029
/** @var EnvironmentHelper|\PHPUnit\Framework\MockObject\MockObject */
3130
private $environmentHelper;
32-
/** @var AppLocator|\PHPUnit\Framework\MockObject\MockObject */
33-
private $appLocator;
34-
/** @var Checker */
35-
private $checker;
3631
/** @var FileAccessHelper|\PHPUnit\Framework\MockObject\MockObject */
3732
private $fileAccessHelper;
3833
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
@@ -46,12 +41,13 @@ class CheckerTest extends TestCase {
4641
/** @var \OC\Files\Type\Detection|\PHPUnit\Framework\MockObject\MockObject */
4742
private $mimeTypeDetector;
4843

44+
private Checker $checker;
45+
4946
protected function setUp(): void {
5047
parent::setUp();
5148
$this->serverVersion = $this->createMock(ServerVersion::class);
5249
$this->environmentHelper = $this->createMock(EnvironmentHelper::class);
5350
$this->fileAccessHelper = $this->createMock(FileAccessHelper::class);
54-
$this->appLocator = $this->createMock(AppLocator::class);
5551
$this->config = $this->createMock(IConfig::class);
5652
$this->appConfig = $this->createMock(IAppConfig::class);
5753
$this->cacheFactory = $this->createMock(ICacheFactory::class);
@@ -71,7 +67,6 @@ protected function setUp(): void {
7167
$this->serverVersion,
7268
$this->environmentHelper,
7369
$this->fileAccessHelper,
74-
$this->appLocator,
7570
$this->config,
7671
$this->appConfig,
7772
$this->cacheFactory,
@@ -186,7 +181,7 @@ public function testVerifyAppSignatureWithValidSignatureData(): void {
186181
->with('integrity.check.disabled', false)
187182
->willReturn(false);
188183

189-
$this->appLocator
184+
$this->appManager
190185
->expects($this->once())
191186
->method('getAppPath')
192187
->with('SomeApp')
@@ -221,7 +216,7 @@ public function testVerifyAppSignatureWithTamperedSignatureData(): void {
221216
->with('integrity.check.disabled', false)
222217
->willReturn(false);
223218

224-
$this->appLocator
219+
$this->appManager
225220
->expects($this->once())
226221
->method('getAppPath')
227222
->with('SomeApp')
@@ -262,7 +257,7 @@ public function testVerifyAppSignatureWithTamperedFiles(): void {
262257
->with('integrity.check.disabled', false)
263258
->willReturn(false);
264259

265-
$this->appLocator
260+
$this->appManager
266261
->expects($this->once())
267262
->method('getAppPath')
268263
->with('SomeApp')
@@ -319,7 +314,7 @@ public function testVerifyAppSignatureWithTamperedFilesAndAlternatePath(): void
319314
->with('integrity.check.disabled', false)
320315
->willReturn(false);
321316

322-
$this->appLocator
317+
$this->appManager
323318
->expects($this->never())
324319
->method('getAppPath')
325320
->with('SomeApp');
@@ -374,7 +369,7 @@ public function testVerifyAppWithDifferentScope(): void {
374369
->with('integrity.check.disabled', false)
375370
->willReturn(false);
376371

377-
$this->appLocator
372+
$this->appManager
378373
->expects($this->once())
379374
->method('getAppPath')
380375
->with('SomeApp')
@@ -415,7 +410,7 @@ public function testVerifyAppWithDifferentScopeAndAlwaysTrustedCore(): void {
415410
->with('integrity.check.disabled', false)
416411
->willReturn(false);
417412

418-
$this->appLocator
413+
$this->appManager
419414
->expects($this->once())
420415
->method('getAppPath')
421416
->with('SomeApp')
@@ -984,7 +979,6 @@ public function testRunInstanceVerification(): void {
984979
$this->serverVersion,
985980
$this->environmentHelper,
986981
$this->fileAccessHelper,
987-
$this->appLocator,
988982
$this->config,
989983
$this->appConfig,
990984
$this->cacheFactory,
@@ -1032,7 +1026,7 @@ public function testRunInstanceVerification(): void {
10321026
$this->assertSame($expected, $app);
10331027
return [];
10341028
});
1035-
$this->appLocator
1029+
$this->appManager
10361030
->expects($this->exactly(2))
10371031
->method('getAppPath')
10381032
->willReturnMap([

tests/lib/IntegrityCheck/Helpers/AppLocatorTest.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)