Skip to content

Commit

Permalink
Dedup install path computation
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 20, 2024
1 parent c7d907b commit 9cea9e5
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/ExtensionInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
$postInstall = function () use ($package) {
$config_file = $this->rcubeConfigFile();
$package_name = $this->getPackageName($package);
$package_dir = $this->getVendorDir() . \DIRECTORY_SEPARATOR . $package_name;
$package_dir = $this->getInstallPath($package);
$extra = $package->getExtra();

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

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

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

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

// restore persistent files
$persistent_files = !empty($extra['roundcube']['persistent-files']) ? $extra['roundcube']['persistent-files'] : ['config.inc.php'];
Expand Down Expand Up @@ -217,7 +216,7 @@ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $
$postUninstall = function () use ($package, $config) {
// post-uninstall: deactivate package
$package_name = $this->getPackageName($package);
$package_dir = $this->getVendorDir() . \DIRECTORY_SEPARATOR . $package_name;
$package_dir = $this->getInstallPath($package);

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

Expand Down Expand Up @@ -400,7 +399,7 @@ private function rcubeRunScript($script, PackageInterface $package)
{
$package_name = $this->getPackageName($package);
$package_type = $package->getType();
$package_dir = $this->getVendorDir() . \DIRECTORY_SEPARATOR . $package_name;
$package_dir = $this->getInstallPath($package);

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

/**
* normalize Roundcube version string.
* Normalize Roundcube version string.
*/
private static function versionNormalize(string $version): string
{
Expand Down

0 comments on commit 9cea9e5

Please sign in to comment.