Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
bash-completion-2.14 / rsync completion bug
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
sdauth
l33t
l33t


Joined: 19 Sep 2018
Posts: 659
Location: Ásgarðr

PostPosted: Sat Jul 06, 2024 12:14 am    Post subject: bash-completion-2.14 / rsync completion bug Reply with quote

Hello,
With two folders "ab" & "ac"

Code:
mkdir ab ac
rsync a [hit tab]
ab/ ac/


-> completion works fine, with possible choices.

but if there is a space in the name, like "a b" & "a c"

Code:
mkdir "a b" "a c"
rsync a [hit tab]


-> Nothing is returned
No problem with ls, cat...
I noticed this only recently with rsync.
I might be wrong... maybe it always has been this way when there is a space in a folder name with rsync bash completion ?

EDIT :

With :
Code:
mkdir "a b" "a c" ad
rsync a [hit tab]
a\ b/  a\ c/  ad/


It seems it is only triggered when the folders all contain spaces, if there is one without it (ad), then completion works and show the others with spaces.
But then If I type the backslash :
Code:
rsync a\ [hit tab]

then it shows nothing. (instead of a\ b/ & a\ c/)

Let me know if you see the same behaviour.


Last edited by sdauth on Sat Jul 06, 2024 6:55 am; edited 2 times in total
Back to top
View user's profile Send private message
sdauth
l33t
l33t


Joined: 19 Sep 2018
Posts: 659
Location: Ásgarðr

PostPosted: Sat Jul 06, 2024 6:40 am    Post subject: Reply with quote

Previous versions of bash-completion have already been removed from gentoo tree..
https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=49a7d394d815dc1b17bc50ce0b6fb6f91ce5f7ca

I chrooted in a root snapshot from two months ago (with bash-completion-2.11) and everything works, so I was not hallucinating :lol:
Even when the folders all contain space in name, completion works perfectly, so something is really broken with rsync bash-completion-2.14. Like I said before, no issue with ls, cat..

Code:
mkdir "a b" "a c"
rsync a [hit tab]
a\ b/ a\ c/


Code:
mkdir "a b" "a c" ad
rsync a [hit tab]
a\ b/  a\ c/  ad/


Otherwise, I tried with with a Debian testing chroot -it uses bash-completion-2.14- to rule out an issue with my gentoo setup; I can reproduce the issue too.

edit: https://bugs.gentoo.org/935658


Last edited by sdauth on Sat Jul 06, 2024 1:11 pm; edited 1 time in total
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22853

PostPosted: Sat Jul 06, 2024 11:43 am    Post subject: Reply with quote

When you tested with bash-completion-2.11, did you use the same version of app-shells/bash as when testing bash-completion-2.14? Bash is unfortunately prone to changing default behaviors of various things, so it would be helpful to understand whether a newer version of bash uses different rules for completions, or if this is a regression in the scripts shipped in bash-completion.
Back to top
View user's profile Send private message
sdauth
l33t
l33t


Joined: 19 Sep 2018
Posts: 659
Location: Ásgarðr

PostPosted: Sat Jul 06, 2024 12:59 pm    Post subject: Reply with quote

@Hu:
Good observation,
In old root snapshot (May), I have :

Code:
app-shells/bash-5.1_p16-r6
app-shells/bash-completion-2.11


So I copied latest bash to chrooted /var/cache/binpkgs and installed :

Code:
[binary     U  ] sys-libs/readline-8.2_p10-1 [8.1_p2-r2]
[binary     U  ] app-shells/bash-5.2_p26-r6-1 [5.1_p16-r6] USE="pgo%*"


exit then re-enter chroot, rsync bash-completion works fine. (same as with bash-5.1_p16-r6)

then copied latest bash-completion to chrooted /var/cache/binpkgs and installed :

Code:
[binary     U  ] app-shells/bash-completion-2.14.0-1 [2.11]


exit then re-enter chroot, the issue shows up. rsync completion fails.
So it really seems to be a bash-completion issue rather than bash.
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22853

PostPosted: Sat Jul 06, 2024 2:05 pm    Post subject: Reply with quote

That is encouraging. The rsync completion is a bash script, and the changes between the good and bad versions of that are (probably) shorter than the changes between versions of bash. It may even be possible to test intermediate versions, either from source control or by manually writing a hybrid that has some, but not all, of the latest changes.

Alternatively, since it is a problem in the script, set -x should show exactly what both the good and bad versions do. Find the place(s) where they disagree and, with some luck, that will lead you to the bug. Specific testing instructions:
  • Prepare a test directory that exhibits the problem, like the one you described in the opening post.
  • Enter that directory with the good bash-completion.
  • Run set -x.
  • Reproduce the error. When you hit tab, bash will run the completion function. Due to set -x, bash will trace the statements inside the completion function as it runs. Beware that set -x can be very verbose. Your terminal will likely be scrolled, possibly by multiple screens of output. A long scrollback history in your terminal would be good. Configuring the terminal to save output to a temporary file might be better.
  • Run set +x to disable the extra logging.
  • Enter that directory with the bad bash-completion (or use an equivalent bad directory in a chroot with the bad version). Using the same bash version in both tests is not essential, but may reduce irrelevant differences in the output.
  • Run set -x. Reproduce the error.
  • Compare the two outputs. Beware that there may be places where the code flow is not identical even when the logic is correct in both, so a simple diff -u may return irrelevant results.
You may also want to modify PS4 to increase what is logged. However, some care is required there, since the more you log, the greater the opportunity to log noise that will cause diff to report differences you don't want to see.
Back to top
View user's profile Send private message
sdauth
l33t
l33t


Joined: 19 Sep 2018
Posts: 659
Location: Ásgarðr

PostPosted: Sat Jul 06, 2024 2:12 pm    Post subject: Reply with quote

Thanks for the tip, I'll have a look later. I hope at least bash-completion-2.11.0 can be brought back to the tree until this is fixed. Maybe I'll copy it to my localrepo... I use rsync -a lot- and this is a very nasty bug.
Otherwise, there has been quite a few changes for rsync completion. (and in bash-completion script too..)
changes between 2.11.0 and 2.14.0 (for completions/rsync) | If any bash expert detects something wrong that could explain it. I don't know enough of bash myself.

Code:
diff --git a/completions/rsync b/completions/rsync
index 0bf53898..f471b46b 100644
--- a/completions/rsync
+++ b/completions/rsync
@@ -1,67 +1,75 @@
 # bash completion for rsync                                -*- shell-script -*-
 
-_rsync()
+_comp_cmd_rsync()
 {
-    local cur prev words cword split
-    _init_completion -s -n : || return
+    local cur prev words cword was_split comp_args
+    _comp_initialize -s -n : -- "$@" || return
 
+    local noargopts='!(-*|*[Te]*)'
+    # shellcheck disable=SC2254
     case $prev in
-        --config | --password-file | --include-from | --exclude-from | --files-from | \
-            --log-file | --write-batch | --only-write-batch | --read-batch)
+        --config | --password-file | --include-from | --exclude-from | \
+            --files-from | --log-file | --write-batch | --only-write-batch | \
+            --read-batch)
             compopt +o nospace
-            _filedir
+            _comp_compgen_filedir
             return
             ;;
-        --temp-dir | --compare-dest | --backup-dir | --partial-dir | --copy-dest | \
-            --link-dest | -!(-*)T)
+        --temp-dir | --compare-dest | --backup-dir | --partial-dir | \
+            --copy-dest | --link-dest | -${noargopts}T)
             compopt +o nospace
-            _filedir -d
+            _comp_compgen_filedir -d
             return
             ;;
-        --rsh | -!(-*)e)
+        --rsh | -${noargopts}e)
             compopt +o nospace
-            COMPREPLY=($(compgen -W 'rsh ssh' -- "$cur"))
+            _comp_compgen -- -W 'rsh ssh'
             return
             ;;
         --compress-level)
             compopt +o nospace
-            COMPREPLY=($(compgen -W '{1..9}' -- "$cur"))
+            _comp_compgen -- -W '{1..9}'
+            return
+            ;;
+        --info)
+            _comp_delimited , -W '
+            backup{,0}
+            copy{,0}
+            del{,0}
+            flist{,0,1,2}
+            misc{,0,1,2}
+            mount{,0}
+            name{,0,1,2}
+            nonreg{,0,1}
+            progress{,0,1,2}
+            remove{,0}
+            skip{,0,1,2}
+            stats{,0,1,2,3}
+            symsafe{,0}
+            all{,0,1,2,3,4}
+            none
+            help
+            '
             return
             ;;
     esac
 
-    $split && return
+    [[ $was_split ]] && return
 
-    _expand || return
+    _comp_expand || return
 
     case $cur in
         -*)
-            COMPREPLY=($(compgen -W '--verbose --quiet --no-motd --checksum
-                --archive --recursive --relative --no-implied-dirs
-                --backup --backup-dir= --suffix= --update --inplace --append
-                --append-verify --dirs --old-dirs --links --copy-links
-                --copy-unsafe-links --safe-links --copy-dirlinks
-                --keep-dirlinks --hard-links --perms --executability --chmod=
-                --acls --xattrs --owner --group --devices --copy-devices
-                --specials --times --omit-dir-times --super --fake-super
-                --sparse --dry-run --whole-file --no-whole-file
-                --one-file-system --block-size= --rsh= --rsync-path=
-                --existing --ignore-existing --remove-source-files --delete
-                --delete-before --delete-during --delete-delay --delete-after
-                --delete-excluded --ignore-errors --force --max-delete=
-                --max-size= --min-size= --partial --partial-dir=
-                --delay-updates --prune-empty-dirs --numeric-ids --timeout=
-                --contimeout= --ignore-times --size-only --modify-window=
-                --temp-dir= --fuzzy --compare-dest= --copy-dest= --link-dest=
-                --compress --compress-level= --skip-compress= --cvs-exclude
-                --filter= --exclude= --exclude-from= --include= --include-from=
-                --files-from= --from0 --protect-args --address= --port=
-                --sockopts= --blocking-io --no-blocking-io --stats
-                --8-bit-output --human-readable --progress --itemize-changes
-                --out-format= --log-file= --log-file-format= --password-file=
-                --list-only --bwlimit= --write-batch= --only-write-batch=
-                --read-batch= --protocol= --iconv= --ipv4 --ipv6 --version
-                --help --daemon --config= --no-detach' -- "$cur"))
+            local tmp
+            # Account for the fact that older rsync versions (before cba00be6,
+            # meaning before v3.2.0) contain the following unusual line in
+            # --help:
+            # "(-h) --help                  show this help (-h is --help only if used alone)"
+            _comp_compgen -Rv tmp help - <<<"$("$1" --help 2>&1 | command sed -e 's/^([^)]*)//')"
+
+            _comp_compgen -- -W '"${tmp[@]}"
+                --daemon --old-d{,irs}
+                --no-{blocking-io,detach,whole-file,inc-recursive,i-r}' -X '--no-OPTION'
             [[ ${COMPREPLY-} == *= ]] || compopt +o nospace
             ;;
         *:*)
@@ -73,14 +81,14 @@ _rsync()
                     break
                 fi
             done
-            [[ $shell == ssh ]] && _xfunc ssh _scp_remote_files
+            [[ $shell == ssh ]] && _comp_compgen -x scp remote_files
             ;;
         *)
-            _known_hosts_real -c -a -- "$cur"
-            _xfunc ssh _scp_local_files
+            _comp_compgen_known_hosts -c -a -- "$cur"
+            _comp_compgen -ax scp local_files
             ;;
     esac
 } &&
-    complete -F _rsync -o nospace rsync
+    complete -F _comp_cmd_rsync -o nospace rsync
 
 # ex: filetype=sh
Back to top
View user's profile Send private message
engineermdr
Guru
Guru


Joined: 08 Nov 2003
Posts: 304
Location: Altoona, WI, USA

PostPosted: Fri Sep 27, 2024 3:27 am    Post subject: Reply with quote

This has been driving me crazy. I rolled back too. Thanks!
Back to top
View user's profile Send private message
sdauth
l33t
l33t


Joined: 19 Sep 2018
Posts: 659
Location: Ásgarðr

PostPosted: Fri Nov 08, 2024 1:30 pm    Post subject: Reply with quote

engineermdr wrote:
This has been driving me crazy. I rolled back too. Thanks!

You're welcome, good to know I'm not the only one affected by this!
Yeah, I'm still using the old version too, still not fixed months later... :?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum