spatie/ssh

Bug: Using timeout causes "scp" related commands to fail

iPwnPancakes opened this issue ยท 0 comments

Hello again! ๐Ÿ˜…

So I noticed that while #86 fixed the issue for regular SSH commands, it did not fix the issues within the other commands. While contemplating on a fix, I came across a decision that I would like to get approval on:

$extraOptions seems to be meant to eventually be transformed into a command's flags/options. But since we're leveraging Symfony/Process' timeout, couldn't we just make a private $timeout property, rather than holding the timeout value in $extraOptions?

My rationale is that while I could just duplicate the filtering logic in:

ssh/src/Ssh.php

Lines 242 to 248 in 169a920

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);
}

to:

ssh/src/Ssh.php

Lines 229 to 240 in 169a920

protected function getExtraScpOptions(): string
{
$extraOptions = $this->extraOptions;
if (isset($extraOptions['port'])) {
$extraOptions['port'] = str_replace('-p', '-P', $extraOptions['port']);
}
$extraOptions[] = '-r';
return implode(' ', array_values($extraOptions));
}

I think the better long term solution would be to just hold the value for the timeout in a different place than $extraOptions