diff options
-rwxr-xr-x | kiss | 23 |
1 files changed, 11 insertions, 12 deletions
@@ -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. |