aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordylan.araps@gmail.com <dylan.araps@gmail.com>2020-01-28 14:46:29 +0000
committerdylan.araps@gmail.com <dylan.araps@gmail.com>2020-01-28 14:46:29 +0000
commit16dd754c1102b67e7fbdaa80f0390a5926a40a36 (patch)
tree27b276d9c8a46338f0e9906c1158797f49a7de6d
parent1126f3001400de1162e2f63485f8569dbd72031a (diff)
downloadcpt-16dd754c1102b67e7fbdaa80f0390a5926a40a36.tar.gz
kiss: Move regex escape to func
FossilOrigin-Name: 76fe5c7d95f83bf9de8b66161283d30f48a93144566cafe6db2bdeeb5210a2dc
-rwxr-xr-xkiss23
1 files 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.