kiss: Move regex escape to func

This commit is contained in:
Dylan Araps 2020-01-28 16:46:29 +02:00
parent b8ea154406
commit e97c78ae26
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 11 additions and 12 deletions

23
kiss
View File

@ -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.