From 8203d6d41f9d460470a3f1b107b12dc6a5f95468 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Wed, 8 Dec 2021 20:07:26 -0500 Subject: [PATCH] Revert "CLI-520: [pull:files] not enough free disk space (#713)" This reverts commit d2733ccc3ef0a2b42b1bce3930b51bd0d1e62c8f. --- src/Command/Pull/PullCommandBase.php | 9 +++-- src/Helpers/LocalMachineHelper.php | 39 ------------------- src/Helpers/SshHelper.php | 19 --------- tests/phpunit/src/CommandTestBase.php | 3 -- .../Commands/Pull/PullFilesCommandTest.php | 5 --- 5 files changed, 6 insertions(+), 69 deletions(-) diff --git a/src/Command/Pull/PullCommandBase.php b/src/Command/Pull/PullCommandBase.php index d7fa691ef..1783db100 100644 --- a/src/Command/Pull/PullCommandBase.php +++ b/src/Command/Pull/PullCommandBase.php @@ -675,10 +675,13 @@ protected function rsyncFilesFromCloud($chosen_environment, Closure $output_call * @throws \Acquia\Cli\Exception\AcquiaCliException */ private function checkDiskSpace($environment, $destination_directory, $source_directory): void { - $local_size = $this->localMachineHelper->getDirectoryUsage($destination_directory); - $remote_size = $this->sshHelper->getDirectoryUsage($environment, $source_directory); + $process = $this->localMachineHelper->execute(['du', '-s', $destination_directory], NULL, NULL, FALSE); + $local_size = explode("\t", $process->getOutput())[0]; + $process = $this->sshHelper->executeCommand($environment, ['du', '-s', $source_directory], FALSE); + $remote_size = explode("\t", $process->getOutput())[0]; $delta = $remote_size - $local_size; - $local_free_space = $this->localMachineHelper->getFreeSpace($destination_directory); + $process = $this->localMachineHelper->execute(['df', '--output=avail', '-k', $destination_directory], NULL, NULL, FALSE); + $local_free_space = explode("\n", $process->getOutput())[1]; // Apply a 10% safety margin. if ($delta * 1.1 > $local_free_space) { throw new AcquiaCliException('Not enough free space to pull files from the {environment} environment. diff --git a/src/Helpers/LocalMachineHelper.php b/src/Helpers/LocalMachineHelper.php index d9cdf42e6..f4f06fc06 100644 --- a/src/Helpers/LocalMachineHelper.php +++ b/src/Helpers/LocalMachineHelper.php @@ -438,43 +438,4 @@ public function startBrowser($uri = NULL, $browser = NULL): bool { return FALSE; } - /** - * @param $directory - * - * @return int - * @throws \Acquia\Cli\Exception\AcquiaCliException - */ - public function getFreeSpace($directory): int { - $this->getFilesystem()->mkdir($directory); - $process = $this->execute([ - 'df', - '--output=avail', - '-k', - $directory - ], NULL, NULL, FALSE); - if (!$process->isSuccessful()) { - throw new AcquiaCliException('Failed to get local free space: {error}', ['error' => $process->getErrorOutput()]); - } - return explode("\n", $process->getOutput())[1]; - } - - /** - * @param $directory - * - * @return int - * @throws \Acquia\Cli\Exception\AcquiaCliException - */ - public function getDirectoryUsage($directory): int { - $this->getFilesystem()->mkdir($directory); - $process = $this->execute([ - 'du', - '-s', - $directory - ], NULL, NULL, FALSE); - if (!$process->isSuccessful()) { - throw new AcquiaCliException('Failed to get usage of local files directory: {error}', ['error' => $process->getErrorOutput()]); - } - return explode("\t", $process->getOutput())[0]; - } - } diff --git a/src/Helpers/SshHelper.php b/src/Helpers/SshHelper.php index 1c519f562..f66c5d9a9 100644 --- a/src/Helpers/SshHelper.php +++ b/src/Helpers/SshHelper.php @@ -69,25 +69,6 @@ public function executeCommand($environment, array $command_args, $print_output return $process; } - /** - * @param $environment - * @param $directory - * - * @return int - * @throws \Acquia\Cli\Exception\AcquiaCliException - */ - public function getDirectoryUsage($environment, $directory): int { - $process = $this->executeCommand($environment, [ - 'du', - '-s', - $directory - ], FALSE); - if (!$process->isSuccessful()) { - throw new AcquiaCliException('Failed to get usage of remote files directory: {error}', ['error' => $process->getErrorOutput()]); - } - return explode("\t", $process->getOutput())[0]; - } - /** * Sends a command to an environment via SSH. * diff --git a/tests/phpunit/src/CommandTestBase.php b/tests/phpunit/src/CommandTestBase.php index 1bdf9fae8..aa3f5be44 100644 --- a/tests/phpunit/src/CommandTestBase.php +++ b/tests/phpunit/src/CommandTestBase.php @@ -205,8 +205,6 @@ protected function mockLocalMachineHelper(): ObjectProphecy { $local_machine_helper = $this->prophet->prophesize(LocalMachineHelper::class); $local_machine_helper->useTty()->willReturn(FALSE); $local_machine_helper->getLocalFilepath(Path::join($this->dataDir, 'acquia-cli.json'))->willReturn(Path::join($this->dataDir, 'acquia-cli.json')); - $local_machine_helper->getFreeSpace(Argument::any())->willReturn(12345); - $local_machine_helper->getDirectoryUsage(Argument::any())->willReturn(123); return $local_machine_helper; } @@ -216,7 +214,6 @@ protected function mockLocalMachineHelper(): ObjectProphecy { */ protected function mockSshHelper(): ObjectProphecy { $ssh_helper = $this->prophet->prophesize(SshHelper::class); - $ssh_helper->getDirectoryUsage(Argument::any(), Argument::any())->willReturn(123); return $ssh_helper; } diff --git a/tests/phpunit/src/Commands/Pull/PullFilesCommandTest.php b/tests/phpunit/src/Commands/Pull/PullFilesCommandTest.php index 78e0dc910..253fb7f3f 100644 --- a/tests/phpunit/src/Commands/Pull/PullFilesCommandTest.php +++ b/tests/phpunit/src/Commands/Pull/PullFilesCommandTest.php @@ -133,9 +133,6 @@ protected function mockExecuteRsync( string $source_dir, string $destination_dir ): void { - // @todo restore these methods - // @see https://github.com/acquia/cli/issues/714 - /** $process = $this->mockProcess(); $process->getOutput()->willReturn("123\tfiles")->shouldBeCalled(); $local_machine_helper->execute(['du', '-s', $destination_dir . 'files'], NULL, NULL, FALSE) @@ -148,10 +145,8 @@ protected function mockExecuteRsync( $process->getOutput()->willReturn("\tAvail\n12345")->shouldBeCalled(); $local_machine_helper->execute(['df', '--output=avail', '-k', $destination_dir . 'files'], NULL, NULL, FALSE) ->willReturn($process->reveal())->shouldBeCalled(); - **/ $local_machine_helper->checkRequiredBinariesExist(['rsync'])->shouldBeCalled(); - $process = $this->mockProcess(); $command = [ 'rsync', '-rltDvPhe',