aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2025-07-10 09:39:58 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2025-07-10 09:39:58 +0200
commit12c0cfc977fae691fd09fe916d533397ee448d46 (patch)
tree995943aae538ee58601c1e64a0c7f92641dc1b4a
parentc7b83ef2e7134d799cee9af12b5bb1c6be4982cd (diff)
downloadnextcloud-server-12c0cfc977fae691fd09fe916d533397ee448d46.tar.gz
nextcloud-server-12c0cfc977fae691fd09fe916d533397ee448d46.zip
fix: Move getInstallPath to Installer class
This method does not need a public API for now, it’s only used internally. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r--lib/private/Installer.php29
-rw-r--r--lib/private/legacy/OC_App.php15
-rw-r--r--lib/private/legacy/OC_Util.php7
-rw-r--r--tests/lib/InstallerTest.php14
4 files changed, 38 insertions, 27 deletions
diff --git a/lib/private/Installer.php b/lib/private/Installer.php
index 3bbef3252f4..6b736bc104a 100644
--- a/lib/private/Installer.php
+++ b/lib/private/Installer.php
@@ -170,6 +170,18 @@ class Installer {
}
/**
+ * Get the path where to install apps
+ */
+ public function getInstallPath(): ?string {
+ foreach (\OC::$APPSROOTS as $dir) {
+ if (isset($dir['writable']) && $dir['writable'] === true) {
+ return $dir['path'];
+ }
+ }
+ return null;
+ }
+
+ /**
* Downloads an app and puts it into the app directory
*
* @param string $appId
@@ -181,6 +193,11 @@ class Installer {
public function downloadApp(string $appId, bool $allowUnstable = false): void {
$appId = strtolower($appId);
+ $installPath = $this->getInstallPath();
+ if ($installPath === null) {
+ throw new \Exception('No application directories are marked as writable.');
+ }
+
$apps = $this->appFetcher->get($allowUnstable);
foreach ($apps as $app) {
if ($app['id'] === $appId) {
@@ -333,7 +350,7 @@ class Installer {
);
}
- $baseDir = OC_App::getInstallPath() . '/' . $appId;
+ $baseDir = $installPath . '/' . $appId;
// Remove old app with the ID if existent
Files::rmdirr($baseDir);
// Move to app folder
@@ -375,7 +392,7 @@ class Installer {
*/
public function isUpdateAvailable($appId, $allowUnstable = false): string|false {
if ($this->isInstanceReadyForUpdates === null) {
- $installPath = OC_App::getInstallPath();
+ $installPath = $this->getInstallPath();
if ($installPath === null) {
$this->isInstanceReadyForUpdates = false;
} else {
@@ -463,7 +480,13 @@ class Installer {
if (\OCP\Server::get(IAppManager::class)->isShipped($appId)) {
return false;
}
- $appDir = OC_App::getInstallPath() . '/' . $appId;
+
+ $installPath = $this->getInstallPath();
+ if ($installPath === null) {
+ $this->logger->error('No application directories are marked as writable.', ['app' => 'core']);
+ return false;
+ }
+ $appDir = $installPath . '/' . $appId;
Files::rmdirr($appDir);
return true;
} else {
diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php
index d4d7b5d30aa..10b78e2a7ef 100644
--- a/lib/private/legacy/OC_App.php
+++ b/lib/private/legacy/OC_App.php
@@ -238,21 +238,6 @@ class OC_App {
}
/**
- * Get the path where to install apps
- */
- public static function getInstallPath(): ?string {
- foreach (OC::$APPSROOTS as $dir) {
- if (isset($dir['writable']) && $dir['writable'] === true) {
- return $dir['path'];
- }
- }
-
- Server::get(LoggerInterface::class)->error('No application directories are marked as writable.', ['app' => 'core']);
- return null;
- }
-
-
- /**
* Find the apps root for an app id.
*
* If multiple copies are found, the apps root the latest version is returned.
diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php
index 948dfcf7926..da89365478c 100644
--- a/lib/private/legacy/OC_Util.php
+++ b/lib/private/legacy/OC_Util.php
@@ -345,9 +345,10 @@ class OC_Util {
// Check if there is a writable install folder.
if ($config->getValue('appstoreenabled', true)) {
- if (OC_App::getInstallPath() === null
- || !is_writable(OC_App::getInstallPath())
- || !is_readable(OC_App::getInstallPath())
+ $installPath = \OCP\Server::get(\OC\Installer::class)->getInstallPath();
+ if ($installPath === null
+ || !is_writable($installPath)
+ || !is_readable($installPath)
) {
$errors[] = [
'error' => $l->t('Cannot write into "apps" directory.'),
diff --git a/tests/lib/InstallerTest.php b/tests/lib/InstallerTest.php
index 1813d2cd151..06163cdaedb 100644
--- a/tests/lib/InstallerTest.php
+++ b/tests/lib/InstallerTest.php
@@ -92,12 +92,7 @@ class InstallerTest extends TestCase {
// Read the current version of the app to check for bug #2572
Server::get(IAppManager::class)->getAppVersion('testapp', true);
- // Extract app
- $pathOfTestApp = __DIR__ . '/../data/testapp.zip';
- $tar = new ZIP($pathOfTestApp);
- $tar->extract(\OC_App::getInstallPath());
-
- // Install app
+ // Build installer
$installer = new Installer(
Server::get(AppFetcher::class),
Server::get(IClientService::class),
@@ -106,6 +101,13 @@ class InstallerTest extends TestCase {
Server::get(IConfig::class),
false
);
+
+ // Extract app
+ $pathOfTestApp = __DIR__ . '/../data/testapp.zip';
+ $tar = new ZIP($pathOfTestApp);
+ $tar->extract($installer->getInstallPath());
+
+ // Install app
$this->assertNull(Server::get(IConfig::class)->getAppValue('testapp', 'enabled', null), 'Check that the app is not listed before installation');
$this->assertSame('testapp', $installer->installApp(self::$appid));
$this->assertSame('no', Server::get(IConfig::class)->getAppValue('testapp', 'enabled', null), 'Check that the app is listed after installation');