aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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