refactor: direct roster lookups in cmd_role and cmd_who

cmd_role's TMUX-socket match and cmd_who's --socket branch each walked
every roster via roster_list to find the one record they already knew
the path to. Read that record directly instead. roster_read still
validates the dir basename and ownership, so a non-party socket falls
through to cmd_role's existing fallback loop.
This commit is contained in:
veg 2026-09-21 09:42:03 +00:00
parent fb92ea1ae7
commit c28101e2e8

16
party
View file

@ -1648,7 +1648,7 @@ cmd_who() {
# roster_read overwrites these with the same values on success.
RR_HOST_USER="${stripped%%:*}"
RR_PARTY_NAME="${stripped#*:}"
rec=$(roster_record_path "$RR_HOST_USER" "$RR_PARTY_NAME")
rec="${sock%/*}/roster"
roster_read "$rec" 2>/dev/null || true
elif [ -n "$partyname" ]; then
find_party_by_name "$partyname" || exit 1
@ -1740,12 +1740,14 @@ EOF
host_sess=''
if [ -n "${TMUX:-}" ]; then
tmux_sock="${TMUX%%,*}"
for rec in $(roster_list); do
roster_read "$rec" || continue
[ "$(party_conn_state "$RR_SOCKET")" != dead ] || continue
[ "$RR_SOCKET" = "$tmux_sock" ] || continue
sock="$RR_SOCKET"; host_sess="$RR_PARTY_NAME"; break
done
# Direct read rather than a roster_list walk: roster_read already
# validates the dir basename/ownership and returns 1 for a
# non-party path, so a personal tmux socket simply falls through
# to the fallback loop below.
if roster_read "${tmux_sock%/sock}/roster" \
&& [ "$(party_conn_state "$RR_SOCKET")" != dead ]; then
sock="$RR_SOCKET"; host_sess="$RR_PARTY_NAME"
fi
fi
if [ -z "$sock" ]; then
for rec in $(roster_list); do