Skip to content

fix(rsync,ssh,sshfs): do not generate regular files *'\' as dirs #1397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

akinomyoga
Copy link
Collaborator

This was a part of #1371 but was separated. Waiting for #1396.

Details are described in the commit message.

@akinomyoga akinomyoga changed the title [Waiting for #1396] fix(rsync,ssh,sshfs): do not generate regular files *'\' as dirs fix(rsync,ssh,sshfs): do not generate regular files *'\' as dirs Jun 17, 2025
@akinomyoga akinomyoga marked this pull request as ready for review June 17, 2025 12:01
@akinomyoga akinomyoga requested a review from scop June 17, 2025 12:01
@yedayak
Copy link
Collaborator

yedayak commented Jun 17, 2025

Maybe add a test with remote files for scp?

In sed, /[^\/]/ does not mean "a character that is not a slash".  It
means "a character that is not a backslash or a slash".  In the
bracket expressions [...], slashes do not need to be escaped by a
backslash, and also, a backslash is treated literally.  We should
instead use /[^/]/.
else
# escape problematic characters; remove executables, aliases, pipes
# and sockets; add space at end of file names
# shellcheck disable=SC2090
_files=$(ssh -o 'Batchmode yes' "$_userhost" \
command ls -aF1dL "$_path*" 2>/dev/null |
command sed -e 's/'"$_comp_cmd_scp__path_esc"'/'"$_escape_replacement"'/g' -e 's/[*@|=]$//g' \
-e 's/[^\/]$/& /g')
-e 's/[^/]$/& /g')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to add a test for this if-branch, but it seems difficult to test it within the current test framework. This branch tries to append a space when it is not a directory, but bash-completion's test framework removes the trailing whitespace when it extracts the generated completions. As a result, we cannot detect whether a suffix space is added by the completion function or not.

)"
else
_comp_compgen -RU files split -l -- "$(
command ls -aF1dL "${files[@]}" 2>/dev/null |
command sed -e "s/$_comp_cmd_scp__path_esc/\\\\&/g" \
-e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' -e "s/^/${1-}/"
-e 's/[*@|=]$//g' -e 's/[^/]$/& /g' -e "s/^/${1-}/"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test for the local-path generation without -d has the same issue. We cannot check the trailing space within the current test framework.

@akinomyoga
Copy link
Collaborator Author

distcheck (centos7) - Action #2979

E               AssertionError: Unexpected output: [bash: COMPREPLY[@]: unbound variable

E               /@]

Yeah, this is actually the same error as the nounset in #1359 (comment). I added a fix in commit 2c54a45.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants