aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordylan.araps@gmail.com <dylan.araps@gmail.com>2020-01-28 13:41:10 +0000
committerdylan.araps@gmail.com <dylan.araps@gmail.com>2020-01-28 13:41:10 +0000
commitb94aa33b493b50906261aec4df824602d617d1a3 (patch)
tree46b16bbd63a930220da777653b827547e3857afd
parentbddf2d184755ea2c5818326dab422f1ee7be963d (diff)
downloadcpt-b94aa33b493b50906261aec4df824602d617d1a3.tar.gz
kiss: alternatives: initial working solution
FossilOrigin-Name: 2bd207d7de9a96dd1a679d731397a4d5f2e526a91b10a026d01c72f0b5c84f50
-rwxr-xr-xkiss37
1 files changed, 35 insertions, 2 deletions
diff --git a/kiss b/kiss
index a6a013d..a1ba40f 100755
--- a/kiss
+++ b/kiss
@@ -822,14 +822,47 @@ pkg_conflicts() {
}
pkg_swap() {
+ # Swap between package alternatives.
+
# Check to see if the package is installed. This
# will exit with an error if it is not.
pkg_list "$1" >/dev/null
alt=$(printf %s "$1$2" | sed 's|/|>|g')
+ cd "$sys_db/../choices"
- [ -f "$sys_db/../choices/$alt" ] ||
+ [ -f "$alt" ] || [ -h "$alt" ] ||
die "Alternative '$1 $2' doesn't exist"
+
+ if [ -f "$2" ]; then
+ # Figure out which package owns the file we are going to
+ # swap for another package's.
+ #
+ # Print the full path to the manifest file which contains
+ # the match to our search.
+ pkg_owns=$(set +f; "$grep" -lFx "$2" "$sys_db/"*/manifest) ||:
+
+ # Extract the package name from the path above.
+ pkg_owns=${pkg_owns%/*}
+ pkg_owns=${pkg_owns##*/}
+
+ [ "$pkg_owns" ] ||
+ die "File '$2' exists on filesystem but isn't owned"
+
+ log "Swapping '$2' from '$pkg_owns' to '$1'"
+
+ # Convert the current owner to an alternative and rewrite
+ # its manifest file to reflect this.
+ dosu mv -f "'$2'" "'$pkg_owns>${alt#*>}'"
+ dosu sed -i "'s|$2|$PWD/$pkg_owns>${alt#*>}|'" \
+ "'../installed/$pkg_owns/manifest'"
+ fi
+
+ # Convert the desired alternative to a real file and rewrite
+ # the manifest file to reflect this. The reverse of above.
+ dosu mv -f "'$alt'" "'$2'"
+ dosu sed -i "'s|$PWD/$alt|$2|'" \
+ "'../installed/$1/manifest'"
}
pkg_remove() {
@@ -1195,7 +1228,7 @@ args() {
# Go over each alternative and format the file
# name for listing. (pkg_name>usr>bin>ls)
for pkg in *; do
- [ -f "$pkg" ] &&
+ [ "$pkg" = '*' ] ||
printf '%s\n' "$pkg" | sed 's|>| /|;s|>|/|g'
done
fi