Skip to content

Commit c28a187

Browse files
authored
Merge pull request #89 from iPwnPancakes/main
Fix: Setting timeout causes scp commands to fail
2 parents 169a920 + ba7a87f commit c28a187

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/Ssh.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class Ssh
2020

2121
protected Closure $onOutput;
2222

23+
private int $timeout = 0;
24+
2325
public function __construct(string $user, string $host, int $port = null)
2426
{
2527
$this->user = $user;
@@ -96,7 +98,7 @@ public function enableStrictHostKeyChecking(): self
9698

9799
public function setTimeout(int $timeout): self
98100
{
99-
$this->extraOptions['timeout'] = $timeout;
101+
$this->timeout = $timeout;
100102

101103
return $this;
102104
}
@@ -241,10 +243,7 @@ protected function getExtraScpOptions(): string
241243

242244
protected function getExtraOptions(): array
243245
{
244-
// Removed timeout from extra options; it's only used as a value for Symfony\Process, not as an SSH option
245-
$extraOptions = array_filter($this->extraOptions, fn ($key) => $key !== 'timeout', ARRAY_FILTER_USE_KEY);
246-
247-
return array_values($extraOptions);
246+
return array_values($this->extraOptions);
248247
}
249248

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

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

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

tests/SshTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,9 @@
151151

152152
assertMatchesSnapshot($command);
153153
});
154+
155+
it('does not alter scp command when setting timeout', function () {
156+
$command = $this->ssh->setTimeout(10)->getUploadCommand('.env', 'spatie.be/current/.env');
157+
158+
assertMatchesSnapshot($command);
159+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scp -r .env user@example.com:spatie.be/current/.env

0 commit comments

Comments
 (0)