From 22d96abf58781dc2bbfa094130e2c1b548d2b544 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 19 Jul 2021 16:42:57 +0300 Subject: [PATCH] kiss: fix regex error 1. Matching of owner was .*$ to accomodate pkg_fix_deps's partial path resolution (/lib instead of /usr/lib). Code now changed to search fully resolved paths. 2. Our matching is now fixed strings and whole line. This removes the possibility of false-positives due to partial matching by prior regex (/bin/ls -> /usr/local/bin/ls (wrong file!)) 3. This should be faster (no more regex, now full line matches). Closes #241 --- kiss | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/kiss b/kiss index 14bec48..fa1b8db 100755 --- a/kiss +++ b/kiss @@ -142,13 +142,27 @@ as_user() { pkg_owner() { ok "$2" || { set +f; set -f -- "$1" "$sys_db"/*/manifest; } - _owns=$(grep -l "$@") + _owns=$(grep -lxF "$@") _owns=${_owns%/*} _owns=${_owns##*/} ok "$_owns" } +resolve_path() { + _rpath=$KISS_ROOT/${1#/} + + # Attempt to resolve symlinks by using 'cd'. + # If this fails, fallback to the file's parent + # directory. + cd -P "${_rpath%/*}" 2>/dev/null || PWD=${_rpath%/*} + + # Final resolved path. + _rpath=${PWD#"$KISS_ROOT"}/${_rpath##*/} + + cd "$OLDPWD" +} + run_hook() { # Run all hooks in KISS_HOOK (a colon separated # list of absolute file paths). @@ -671,11 +685,13 @@ pkg_fix_deps() { continue esac + resolve_path "$lib" + # Skip file if owned by current package - ! pkg_owner "/${lib#/}\$" manifest || + ! pkg_owner -e "$_rpath" manifest || continue - ! pkg_owner "/${lib#/}\$" "$@" || + ! pkg_owner -e "$_rpath" "$@" || printf '%s\n' "$_owns" esac done </dev/null || PWD=${file%/*} - - # Print the file with all symlinks in its path - # resolved to their real locations. - printf '%s\n' "${PWD#"$KISS_ROOT"}/${file##*/}" + resolve_path "$file" + printf '%s\n' "$_rpath" esac done < "$PWD/$pkg_db/$_pkg/manifest" > "$_tmp_file_pre" cd "$tar_dir/$_pkg" @@ -1134,7 +1142,7 @@ pkg_swap() { die "Alternative '$1 ${2:-null}' doesn't exist" if [ -f "$KISS_ROOT$2" ]; then - pkg_owner "/${2#/}\$" || + pkg_owner "/${2#/}" || die "File '$2' exists on filesystem but isn't owned" log "Swapping '$2' from '$_owns' to '$1'"