fix(scp): Use less escaping for filenames when not needed - #1701
Conversation
d987ac8 to
39b4830
Compare
akinomyoga
left a comment
There was a problem hiding this comment.
Thank you for updating.
scop
left a comment
There was a problem hiding this comment.
Let's also mention remote filenames in the PR title and commit message. I think I'd rephrase it something like "use less remote filename escaping where supported", as the "less ... not needed" reads odd to me.
| fi | ||
| done | ||
|
|
||
| if [[ $legacy_scp || ! $("$1" --usage 2>&1) =~ scp\ \[-[^]]*O ]]; then |
There was a problem hiding this comment.
I wonder if the logic with $legacy_scp here is the wrong way around.
I'm assuming the intent is to do less escaping if we found -O was given.
So with that, shouldn't we be doing this instead?
| if [[ $legacy_scp || ! $("$1" --usage 2>&1) =~ scp\ \[-[^]]*O ]]; then | |
| if [[ ! $legacy_scp && ! $("$1" --usage 2>&1) =~ scp\ \[-[^]]*O ]]; then |
...and if logically yes, we could flip the if/else around and remove the negations, so
if [[ $legacy_scp || $("$1" --usage 2>&1) =~ scp\ \[-[^]]*O ]]; then
# do the -l here
Also, I find this code with $legacy_scp variable name kind of hard to read, would be better if it had the has_ prefix, but just adding that would kind of make the variable read unclear still. How about something like $has_O_given?
There was a problem hiding this comment.
Er
I'm assuming the intent is to do less escaping if we found -O was given.
...this assumption of mine is false and we want it the other way around, so the original code is fine after all. Will merge with the commit message tweaked.
OpenSSH 9.0 changed the default protocol the "scp" command uses to sftp, which needs less escaping for special characters in remote filenames. Check if the command has the option to use the legacy protocol and do less escaping. If the command line has the "-O" option to use the legacy protocol, we revert to the old behaviour. The extra escaping is necessary for older versions, so we can't do it unconditionally. Fixes: scop#1540
fix(scp): Use less escaping for filenames when not needed
OpenSSH 9.0 changed the default protocol the "scp" command uses to
sftp, which needs less escaping for special characters in remote
filenames. Check if the command has the option to use the legacy
protocol and do less escaping.
If the command line has the "-O" option to use the legacy protocol,
we revert to the old behaviour.
The extra escaping is necessary for older versions, so we can't do it
unconditionally.
Fixes: #1540