From 4efddd04108a760546d0b24a6dd3a4bdc3b5e34c Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 9 Jun 2020 10:02:52 +0300 Subject: [PATCH] kiss: Fix pkg_swap failure. Closes #162 --- kiss | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/kiss b/kiss index dc209ab..950ca0c 100755 --- a/kiss +++ b/kiss @@ -875,10 +875,16 @@ pkg_swap() { # file to reflect this. cp -Pf "$KISS_ROOT/$2" "$pkg_owns>${alt#*>}" - # The separator is the ASCII unit separator which should be safe to - # use as files should never contain this character (I hope to god).. - sed "s^$2$${PWD#"$KISS_ROOT"}/$pkg_owns>${alt#*>}" \ - "../installed/$pkg_owns/manifest" | sort -r > "$mak_dir/.$1" + # Replace the matching line in the manifest with the desired replacement. + # This used to be a 'sed' call which turned out to be a little + # error-prone in some cases. This new method is a tad slower but ensures + # we never wipe the file due to a command error. + while read -r line; do + case $line in + "$2") printf '%s\n' "${PWD#"$KISS_ROOT"}/$pkg_owns>${alt#*>}" ;; + *) printf '%s\n' "$line" ;; + esac + done < "../installed/$pkg_owns/manifest" | sort -r > "$mak_dir/.$1" mv -f "$mak_dir/.$1" "../installed/$pkg_owns/manifest" fi @@ -887,10 +893,16 @@ pkg_swap() { # file to reflect this. The reverse of above. mv -f "$alt" "$KISS_ROOT/$2" - # The separator is the ASCII unit separator which should be safe to use - # as files should never contain this character (I hope to god). - sed "s${PWD#"$KISS_ROOT"}/$alt$2" \ - "../installed/$1/manifest" | sort -r > "$mak_dir/.$1" + # Replace the matching line in the manifest with the desired replacement. + # This used to be a 'sed' call which turned out to be a little error-prone + # in some cases. This new method is a tad slower but ensures we never wipe + # the file due to a command error. + while read -r line; do + case $line in + "${PWD#"$KISS_ROOT"}/$alt") printf '%s\n' "$2" ;; + *) printf '%s\n' "$line" ;; + esac + done < "../installed/$1/manifest" | sort -r > "$mak_dir/.$1" mv -f "$mak_dir/.$1" "../installed/$1/manifest" }