Skip to content

Commit c98d6e4

Browse files
committed
Dedup install path computation
1 parent c7d907b commit c98d6e4

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

src/ExtensionInstaller.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
abstract class ExtensionInstaller extends LibraryInstaller
1616
{
17+
/** @var string|null */
1718
private $roundcubemailInstallPath;
1819

20+
/** @var string */
1921
protected $composer_type;
2022

2123
protected function setRoundcubemailInstallPath(InstalledRepositoryInterface $installedRepo): void
@@ -46,13 +48,17 @@ protected function getRoundcubemailInstallPath(): string
4648

4749
public function getInstallPath(PackageInterface $package)
4850
{
49-
if (!$this->supports($package->getType()) || $this->roundcubemailInstallPath === null /* install path is not known at download phase */) {
51+
if (
52+
!$this->supports($package->getType())
53+
|| $this->roundcubemailInstallPath === null // install path is not known at download phase
54+
) {
5055
return parent::getInstallPath($package);
5156
}
5257

5358
$vendorDir = $this->getVendorDir();
5459

55-
return sprintf('%s/%s', $vendorDir, $this->getPackageName($package));
60+
return $vendorDir . \DIRECTORY_SEPARATOR
61+
. str_replace('/', \DIRECTORY_SEPARATOR, $this->getPackageName($package));
5662
}
5763

5864
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
@@ -70,7 +76,7 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
7076
$postInstall = function () use ($package) {
7177
$config_file = $this->rcubeConfigFile();
7278
$package_name = $this->getPackageName($package);
73-
$package_dir = $this->getVendorDir() . \DIRECTORY_SEPARATOR . $package_name;
79+
$package_dir = $this->getInstallPath($package);
7480
$extra = $package->getExtra();
7581

7682
if (is_writable($config_file) && \PHP_SAPI === 'cli' && $this->confirmInstall($package_name)) {
@@ -143,16 +149,15 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
143149
$fs = new Filesystem();
144150

145151
// backup persistent files e.g. config.inc.php
146-
$package_name = $this->getPackageName($initial);
147-
$package_dir = $this->getVendorDir() . \DIRECTORY_SEPARATOR . $package_name;
152+
$package_dir = $this->getInstallPath($initial);
148153
$temp_dir = $package_dir . '-' . sprintf('%010d%010d', mt_rand(), mt_rand());
149154

150155
// make a backup of existing files (for restoring persistent files)
151156
$fs->copy($package_dir, $temp_dir);
152157

153158
$postUpdate = function () use ($target, $extra, $fs, $temp_dir) {
154159
$package_name = $this->getPackageName($target);
155-
$package_dir = $this->getVendorDir() . \DIRECTORY_SEPARATOR . $package_name;
160+
$package_dir = $this->getInstallPath($target);
156161

157162
// restore persistent files
158163
$persistent_files = !empty($extra['roundcube']['persistent-files']) ? $extra['roundcube']['persistent-files'] : ['config.inc.php'];
@@ -217,7 +222,7 @@ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $
217222
$postUninstall = function () use ($package, $config) {
218223
// post-uninstall: deactivate package
219224
$package_name = $this->getPackageName($package);
220-
$package_dir = $this->getVendorDir() . \DIRECTORY_SEPARATOR . $package_name;
225+
$package_dir = $this->getInstallPath($package);
221226

222227
$this->rcubeAlterConfig($package_name, false);
223228

@@ -400,7 +405,7 @@ private function rcubeRunScript($script, PackageInterface $package)
400405
{
401406
$package_name = $this->getPackageName($package);
402407
$package_type = $package->getType();
403-
$package_dir = $this->getVendorDir() . \DIRECTORY_SEPARATOR . $package_name;
408+
$package_dir = $this->getInstallPath($package);
404409

405410
// check for executable shell script
406411
if (($scriptfile = realpath($package_dir . \DIRECTORY_SEPARATOR . $script)) && is_executable($scriptfile)) {
@@ -424,7 +429,7 @@ private function rcubeRunScript($script, PackageInterface $package)
424429
}
425430

426431
/**
427-
* normalize Roundcube version string.
432+
* Normalize Roundcube version string.
428433
*/
429434
private static function versionNormalize(string $version): string
430435
{

0 commit comments

Comments
 (0)