Skip to content

Commit

Permalink
Merge pull request #89 from iPwnPancakes/main
Browse files Browse the repository at this point in the history
Fix: Setting timeout causes scp commands to fail
  • Loading branch information
freekmurze authored Jun 19, 2023
2 parents 169a920 + ba7a87f commit c28a187
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Ssh.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Ssh

protected Closure $onOutput;

private int $timeout = 0;

public function __construct(string $user, string $host, int $port = null)
{
$this->user = $user;
Expand Down Expand Up @@ -96,7 +98,7 @@ public function enableStrictHostKeyChecking(): self

public function setTimeout(int $timeout): self
{
$this->extraOptions['timeout'] = $timeout;
$this->timeout = $timeout;

return $this;
}
Expand Down Expand Up @@ -241,10 +243,7 @@ protected function getExtraScpOptions(): string

protected function getExtraOptions(): array
{
// Removed timeout from extra options; it's only used as a value for Symfony\Process, not as an SSH option
$extraOptions = array_filter($this->extraOptions, fn ($key) => $key !== 'timeout', ARRAY_FILTER_USE_KEY);

return array_values($extraOptions);
return array_values($this->extraOptions);
}

protected function wrapArray($arrayOrString): array
Expand All @@ -256,7 +255,7 @@ protected function run(string $command, string $method = 'run'): Process
{
$process = Process::fromShellCommandline($command);

$process->setTimeout($this->extraOptions['timeout'] ?? 0);
$process->setTimeout($this->timeout);

($this->processConfigurationClosure)($process);

Expand Down
6 changes: 6 additions & 0 deletions tests/SshTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,9 @@

assertMatchesSnapshot($command);
});

it('does not alter scp command when setting timeout', function () {
$command = $this->ssh->setTimeout(10)->getUploadCommand('.env', 'spatie.be/current/.env');

assertMatchesSnapshot($command);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scp -r .env [email protected]:spatie.be/current/.env

0 comments on commit c28a187

Please sign in to comment.