From c50e6e4519d7c4bfd8fe1e642bf6c565a0106222 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 18 Jan 2023 13:24:47 -0700 Subject: hstow: speed up unstowing by using more streaming --- bin/hstow | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'bin/hstow') diff --git a/bin/hstow b/bin/hstow index 311fce2a..c10b4907 100755 --- a/bin/hstow +++ b/bin/hstow @@ -50,6 +50,15 @@ if ! command -v readlink >/dev/null; then } 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/' +} + disjoin_hstow_file () { if [ -e "$DIR/$1" ]; then while read -r line; do @@ -148,19 +157,18 @@ unstow () { for file in \ $(find . ! \( -user "$(id -un)" -o -group "$(id -gn)" \) \ -prune -o -type l ! -name . ! -name "$cchars" -print \ - | grep -Ev "$dirs_pat"); do - if readlink "$file" | grep -Eq '^(\.\./)*\.STOW/'"$NAME/"; then - rm "$file" - while true; do - file="$(dirname $file)" - [ "$file" = . ] && break - if [ -z "$(dir_contents $file)" ]; then - rmdir "$file" - else - break - fi - done - fi + | grep -Ev "$dirs_pat" | readlinks | awk -F'\t' \ + '$2 ~ /^(\.\.\/)*\.STOW\/'"$NAME"'\// { print $1 }'); do + rm "$file" + while true; do + file="$(dirname $file)" + [ "$file" = . ] && break + if [ -z "$(dir_contents $file)" ]; then + rmdir "$file" + else + break + fi + done done [ -e "$HOME/.STOW/$NAME" ] && rm "$HOME/.STOW/$NAME" if [ -d "$HOME/.STOW" ] \ -- cgit v1.2.3