From 16dd754c1102b67e7fbdaa80f0390a5926a40a36 Mon Sep 17 00:00:00 2001
From: "dylan.araps@gmail.com" <dylan.araps@gmail.com>
Date: Tue, 28 Jan 2020 14:46:29 +0000
Subject: kiss: Move regex escape to func

FossilOrigin-Name: 76fe5c7d95f83bf9de8b66161283d30f48a93144566cafe6db2bdeeb5210a2dc
---
 kiss | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

(limited to 'kiss')

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.
-- 
cgit v1.2.3