Skip to content

Commit

Permalink
Revert "CLI-520: [pull:files] not enough free disk space (#713)"
Browse files Browse the repository at this point in the history
This reverts commit d2733cc.
  • Loading branch information
grasmash authored Dec 9, 2021
1 parent 7c209b2 commit 8203d6d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 69 deletions.
9 changes: 6 additions & 3 deletions src/Command/Pull/PullCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
39 changes: 0 additions & 39 deletions src/Helpers/LocalMachineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

}
19 changes: 0 additions & 19 deletions src/Helpers/SshHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
3 changes: 0 additions & 3 deletions tests/phpunit/src/CommandTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down
5 changes: 0 additions & 5 deletions tests/phpunit/src/Commands/Pull/PullFilesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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',
Expand Down

0 comments on commit 8203d6d

Please sign in to comment.