From 8ab0e26154e513a9d1f65757be56bc36037b3621 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 19 Jan 2023 09:52:34 -0700 Subject: hstow: readlinks: handle add'l fields, check that input names a link --- bin/hstow | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'bin/hstow') diff --git a/bin/hstow b/bin/hstow index c10b4907..3fce0a72 100755 --- a/bin/hstow +++ b/bin/hstow @@ -53,10 +53,16 @@ fi # Here we unconditionally bypass readlink(1), for speed. # The long regexp is because only BREs have backreferences in POSIX. readlinks () { - while read -r line; do - printf '%s\t%s\n' "$line" "$(ls -ld "$line")" - done | sed \ -'s/\([^\t]*\)\t\([^[:blank:]]\{1,\}[[:blank:]]\{1,\}\)\{8\}\1 -> /\1\t/' + local restc=$1 assume="${2:-false}" first= rest= + while read -r first rest; do + if $assume || [ -h "$first" ]; then + [ -n "$rest" ] && rest="$rest$tab" + rest="$rest$(ls -ld "$first")" + fi + printf '%s\t%s\n' "$first" "$rest" + done | sed 's/^\([^\t]\{1,\}\)\t\('\ +"$(printf "%${restc}s" | sed 's/ /[^\\t]\\{1,\\}\\t/g')"\ +'\)\([^[:blank:]]\{1,\}[[:blank:]]\{1,\}\)\{8\}\1 -> /\1\t\2/' } disjoin_hstow_file () { @@ -157,7 +163,7 @@ unstow () { for file in \ $(find . ! \( -user "$(id -un)" -o -group "$(id -gn)" \) \ -prune -o -type l ! -name . ! -name "$cchars" -print \ - | grep -Ev "$dirs_pat" | readlinks | awk -F'\t' \ + | grep -Ev "$dirs_pat" | readlinks 0 true | awk -F'\t' \ '$2 ~ /^(\.\.\/)*\.STOW\/'"$NAME"'\// { print $1 }'); do rm "$file" while true; do -- cgit v1.2.3