From e97c78ae260ed1487ded7e0698bbba314b636e05 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 28 Jan 2020 16:46:29 +0200 Subject: [PATCH] kiss: Move regex escape to func --- kiss | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/kiss b/kiss index d8d1685..4377345 100755 --- a/kiss +++ b/kiss @@ -148,6 +148,14 @@ dosu() { fi } +regex_escape() { + # Escape all required characters in both the search and + # replace portions of two strings for use in a 'sed' call + # as "plain-text". + sea=$(echo "$1" | sed 's/[]\/$*.^[]/\\&/g') + rep=$(echo "$2" | sed 's/[\/&]/\\&/g') +} + pkg_lint() { # Check that each mandatory file in the package entry exists. log "$1" "Checking repository files" @@ -806,10 +814,7 @@ pkg_conflicts() { # conflicting file. (pkg_name>usr>bin>ls) con_name=$(echo "$con" | sed 's|/|>|g') - # Escape the required patch characters in the file name - # as it will be passed along to 'sed' below. - sea=$(echo "$con" | sed 's/[]\/$*.^[]/\\&/g') - rep=$(echo "/$cho_dir/$p_name$con_name" | sed 's/[\/&]/\\&/g') + regex_escape "$con" "/$cho_dir/$p_name$con_name" # Move the conflicting file to the choices directory # and name it according to the format above. @@ -854,10 +859,7 @@ pkg_swap() { log "Swapping '$2' from '$pkg_owns' to '$1'" - # Escape the required patch characters in the file name - # as it will be passed along to 'sed' below. - sea=$(echo "$2" | sed 's/[]\/$*.^[]/\\&/g') - rep=$(echo "$PWD/$pkg_owns>${alt#*>}" | sed 's/[\/&]/\\&/g') + regex_escape "$2" "$PWD/$pkg_owns>${alt#*>}" # Convert the current owner to an alternative and rewrite # its manifest file to reflect this. @@ -865,10 +867,7 @@ pkg_swap() { dosu sed -i "'s/$sea/$rep/'" "'../installed/$pkg_owns/manifest'" fi - # Escape the required patch characters in the file name - # as it will be passed along to 'sed' below. - sea=$(echo "$PWD/$alt" | sed 's/[]\/$*.^[]/\\&/g') - rep=$(echo "$2" | sed 's/[\/&]/\\&/g') + regex_escape "$PWD/$alt" "$2" # Convert the desired alternative to a real file and rewrite # the manifest file to reflect this. The reverse of above.