From 8dbe19222a8cb76a85afdcafd4be2ec3393570ad Mon Sep 17 00:00:00 2001 From: Wynn Wolf Arbor Date: Tue, 21 Jan 2020 21:22:49 +0100 Subject: Make list_active more robust A couple of small changes to this function should make it more robust in the long run: 1) We no longer filter the symlinks with find(1), instead combining filtering and substituting in sed(1) 2) We use the absolute path (as given by readlink -f) such that we can anchor the regular expression pattern to avoid unwanted substitution. 3) Instead of hard-coding paths we now use STOW_DIR (and STOW_DIR/.. for the target directory) 4) To avoid unnecessary complexity, we no longer let the user override STOW_DIR. This tool is supposed to be used with the canonical /etc/portage/stow location --- bosun | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bosun b/bosun index 2b913b0..7d8efeb 100755 --- a/bosun +++ b/bosun @@ -1,7 +1,6 @@ #!/bin/sh -# allow overriding STOW_DIR by the user -export STOW_DIR=${STOW_DIR:-/etc/portage/stow} +export STOW_DIR=/etc/portage/stow need_root() { if test "$(id -u)" -ne 0; then @@ -46,10 +45,12 @@ list() { } list_active() { + # Note: we de not escape any special characters in $STOW_DIR since it is + # assumed we are in full control of its contents. # XXX: -r for xargs is a GNU extension - find /etc/portage/ -lname "*stow/*" -print0 2>/dev/null \ - | xargs -r0 readlink \ - | sed 's:.*stow/\([^/]\+\)/.*:\1:' \ + find "$STOW_DIR/.." -type l -print0 2>/dev/null \ + | xargs -r0 readlink -f \ + | sed -n ":^$STOW_DIR: s:^$STOW_DIR/\([^/]\+\)/.*:\1:p" \ | sort -u } -- cgit v1.2.3-2-gb3c3