Skip to content

Commit

Permalink
CLI-1282: [remote:aliases:download] warning on read-only directory (#…
Browse files Browse the repository at this point in the history
…1718)

* CLI-1282: [remote:aliases:download] warning on read-only directory

* add test

* bad merge

* bad bad merge

* exclude test on windows
  • Loading branch information
danepowell authored Apr 2, 2024
1 parent 8bb887e commit 4fe057a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Command/Remote/AliasesDownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ protected function downloadDrush9Aliases(InputInterface $input, string $aliasVer
$drushFiles[] = $baseDir . '/' . $file->getFileName();
}
}
$archive->extractTo($drushAliasesDir, $drushFiles, TRUE);
try {
// Throws warnings on permissions errors.
@$archive->extractTo($drushAliasesDir, $drushFiles, TRUE);
}
catch (\Exception) {
throw new AcquiaCliException('Could not extract aliases to {destination}', ['destination' => $drushAliasesDir]);
}
}

protected function downloadDrush8Aliases(string $aliasVersion, string $drushArchiveTempFilepath, string $drushAliasesDir): void {
Expand Down
3 changes: 3 additions & 0 deletions src/EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public function onConsoleError(ConsoleErrorEvent $event): void {
case 'This machine is not yet authenticated with Site Factory.':
$this->helpMessages[] = 'Run `acli auth:acsf-login` to re-authenticate with Site Factory.';
break;
case 'Could not extract aliases to {destination}':
$this->helpMessages[] = 'Check that you have write access to the directory';
break;
case 'Invalid key in datastore at {filepath}':
$this->helpMessages[] = 'Delete the datastore and run this command again.';
break;
Expand Down
23 changes: 23 additions & 0 deletions tests/phpunit/src/Commands/Remote/AliasesDownloadCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Command\Remote\AliasesDownloadCommand;
use Acquia\Cli\Exception\AcquiaCliException;
use Acquia\Cli\Tests\CommandTestBase;
use GuzzleHttp\Psr7\Utils;
use Phar;
Expand Down Expand Up @@ -82,7 +83,29 @@ public function testRemoteAliasesDownloadCommand(array $inputs, array $args, str
$this->assertFileDoesNotExist($drushArchiveFilepath);
$this->assertFileExists($destinationDir);
$this->assertStringContainsString('Cloud Platform Drush aliases installed into ' . $destinationDir, $output);
}

/**
* @requires OS linux|darwin
*/
public function testRemoteAliasesDownloadFailed(): void {
$drushAliasesFixture = Path::canonicalize(__DIR__ . '/../../../../fixtures/drush-aliases');
$drushAliasesTarballFixtureFilepath = tempnam(sys_get_temp_dir(), 'AcquiaDrushAliases');
$archiveFixture = new PharData($drushAliasesTarballFixtureFilepath . '.tar');
$archiveFixture->buildFromDirectory($drushAliasesFixture);
$archiveFixture->compress(Phar::GZ);

$stream = Utils::streamFor(file_get_contents($drushAliasesTarballFixtureFilepath . '.tar.gz'));
$this->clientProphecy->addQuery('version', '9');
$this->clientProphecy->stream('get', '/account/drush-aliases/download')->willReturn($stream);

$destinationDir = Path::join($this->acliRepoRoot, 'drush');
$sitesDir = Path::join($destinationDir, 'sites');
mkdir($sitesDir, 0777, TRUE);
chmod($sitesDir, 000);
$this->expectException(AcquiaCliException::class);
$this->expectExceptionMessage("Could not extract aliases to $destinationDir");
$this->executeCommand(['--all' => TRUE, '--destination-dir' => $destinationDir], ['9']);
}

}
4 changes: 4 additions & 0 deletions tests/phpunit/src/Misc/ExceptionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public function providerTestHelp(): array {
new AcquiaCliException('This machine is not yet authenticated with Site Factory.'),
'Run `acli auth:acsf-login` to re-authenticate with Site Factory.',
],
[
new AcquiaCliException('Could not extract aliases to {destination}'),
'Check that you have write access to the directory',
],
[
new AcquiaCliException('Invalid key in datastore at {filepath}'),
'Delete the datastore and run this command again.',
Expand Down

0 comments on commit 4fe057a

Please sign in to comment.