diff --git a/bin/acli b/bin/acli index 53ce47b13..5edac2683 100755 --- a/bin/acli +++ b/bin/acli @@ -60,6 +60,9 @@ $input = new ArgvInput(); if (!getenv('HOME')) { putenv('HOME=' . LocalMachineHelper::getHomeDir()); } +if (!getenv('ACLI_HOME')) { + putenv('ACLI_HOME=' . LocalMachineHelper::getConfigDir()); +} $kernel = new Kernel('prod', false); // Handle a clear-kernel-cache pseudo command. This isn't implemented as a true console diff --git a/config/prod/services.yml b/config/prod/services.yml index 7b3554ad1..1b238d670 100644 --- a/config/prod/services.yml +++ b/config/prod/services.yml @@ -1,7 +1,7 @@ --- parameters: env(ACLI_REPO_ROOT): "%kernel.project_dir%" - app.data_dir: "%env(HOME)%/.acquia" + app.data_dir: "%env(ACLI_HOME)%" app.project_dir: "%env(ACLI_REPO_ROOT)%" app.ssh_dir: "%env(HOME)%/.ssh" app.acli_config_filename: '.acquia-cli.yml' diff --git a/src/Helpers/LocalMachineHelper.php b/src/Helpers/LocalMachineHelper.php index 61d3874c2..5ea4e074d 100644 --- a/src/Helpers/LocalMachineHelper.php +++ b/src/Helpers/LocalMachineHelper.php @@ -236,6 +236,18 @@ public static function getHomeDir(): string { return $home; } + public static function getConfigDir(): string { + $home = self::getHomeDir(); + $legacyDir = Path::join($home, '.acquia'); + if (file_exists($legacyDir)) { + return $legacyDir; + } + if ($xdgHome = getenv('XDG_CONFIG_HOME')) { + return Path::join($xdgHome, 'acquia'); + } + return Path::join($home, '.config', 'acquia'); + } + /** * Get the project root directory for the working directory. * diff --git a/tests/phpunit/src/Misc/LocalMachineHelperTest.php b/tests/phpunit/src/Misc/LocalMachineHelperTest.php index 13407a942..9036737ac 100644 --- a/tests/phpunit/src/Misc/LocalMachineHelperTest.php +++ b/tests/phpunit/src/Misc/LocalMachineHelperTest.php @@ -96,4 +96,25 @@ public function testHomeDirWindowsMing(): void { LocalMachineHelper::getHomeDir(); } + public function testConfigDirLegacy(): void { + self::setEnvVars(['HOME' => 'vfs://root']); + $configDir = LocalMachineHelper::getConfigDir(); + $this->assertEquals('vfs://root/.acquia', $configDir); + } + + public function testConfigDirFromXdg(): void { + self::setEnvVars(['XDG_CONFIG_HOME' => 'vfs://root/.config']); + $configDir = LocalMachineHelper::getConfigDir(); + $this->assertEquals('vfs://root/.config/acquia', $configDir); + } + + public function testConfigDirDefault(): void { + self::setEnvVars(['HOME' => 'vfs://root']); + self::unsetEnvVars(['XDG_CONFIG_HOME']); + unlink('vfs://root/.acquia/cloud_api.conf'); + rmdir('vfs://root/.acquia'); + $configDir = LocalMachineHelper::getConfigDir(); + $this->assertEquals('vfs://root/.config/acquia', $configDir); + } + } diff --git a/tests/phpunit/src/TestBase.php b/tests/phpunit/src/TestBase.php index 78d5de29f..0f0e36ff4 100644 --- a/tests/phpunit/src/TestBase.php +++ b/tests/phpunit/src/TestBase.php @@ -181,7 +181,7 @@ protected function setUp(): void { $this->vfsRoot = vfsStream::setup(); $this->projectDir = vfsStream::newDirectory('project')->at($this->vfsRoot)->url(); $this->sshDir = vfsStream::newDirectory('ssh')->at($this->vfsRoot)->url(); - $this->dataDir = vfsStream::newDirectory('data')->at($this->vfsRoot)->url(); + $this->dataDir = vfsStream::newDirectory('.acquia')->at($this->vfsRoot)->url(); $this->cloudConfigFilepath = Path::join($this->dataDir, 'cloud_api.conf'); $this->acliConfigFilename = '.acquia-cli.yml'; $this->acliConfigFilepath = Path::join($this->projectDir, $this->acliConfigFilename);