mirror of
https://github.com/nextcloud/server.git
synced 2026-06-14 19:20:35 -04:00
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>
This commit is contained in:
parent
c7b83ef2e7
commit
12c0cfc977
4 changed files with 38 additions and 27 deletions
|
|
@ -169,6 +169,18 @@ class Installer {
|
|||
return $matches[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -237,21 +237,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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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.'),
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in a new issue