1
0
mirror of https://codeberg.org/kiss-community/kiss synced 2024-12-25 00:20:05 -07:00

kiss: pkg_conflicts cleanup

This commit is contained in:
Dylan Araps 2020-09-14 21:24:35 +03:00
parent 737ef0c147
commit 3f76c1ee0a
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E

71
kiss
View File

@ -720,26 +720,21 @@ pkg_conflicts() {
while read -r file; do while read -r file; do
file=$KISS_ROOT/${file#/} file=$KISS_ROOT/${file#/}
# Skip all directories. case $file in
case $file in */) continue; esac *[!/])
cd -P "${file%/*}" 2>/dev/null ||
PWD=${file%/*}
# Attempt to resolve symlinks by using 'cd'.
# If this fails, fallback to the file's parent
# directory.
cd -P "${file%/*}" 2>/dev/null || PWD=${file%/*}
# Print the file with all symlinks in its path
# resolved to their real locations.
printf '%s\n' "${PWD#"$KISS_ROOT"}/${file##*/}" printf '%s\n' "${PWD#"$KISS_ROOT"}/${file##*/}"
;;
esac
done < "$tar_dir/$1/$pkg_db/$1/manifest" > "$mak_dir/$pid-m" done < "$tar_dir/$1/$pkg_db/$1/manifest" > "$mak_dir/$pid-m"
set +f set +f
set -f "$sys_db"/*/manifest set -f "$sys_db"/*/manifest
# Generate a list of all installed package manifests and remove the # Generate a list of all installed package manifests and remove the
# current package from the list. This is the simplest method of # current package from the list.
# dropping an item from the argument list. The one downside is that
# it cannot live in a function due to scoping of arguments.
for manifest do for manifest do
shift shift
@ -749,44 +744,22 @@ pkg_conflicts() {
set -- "$@" "$manifest" set -- "$@" "$manifest"
done done
# Return here if there is nothing to check conflicts against.
[ "$#" != 0 ] || return 0 [ "$#" != 0 ] || return 0
# Store the list of found conflicts in a file as we'll be using the # Store the list of found conflicts in a file for reuse.
# information multiple times. Storing things in the cache dir allows
# us to be lazy as they'll be automatically removed on script end.
grep -Fxf "$mak_dir/$pid-m" -- "$@" 2>/dev/null > "$mak_dir/$pid-c" ||: grep -Fxf "$mak_dir/$pid-m" -- "$@" 2>/dev/null > "$mak_dir/$pid-c" ||:
# Enable alternatives automatically if it is safe to do so. if [ "$KISS_CHOICE" != 0 ] && [ -s "$mak_dir/$pid-c" ]; then
# This checks to see that the package that is about to be installed # Choices are dynamically created and destroyed.
# doesn't overwrite anything it shouldn't in '/var/db/kiss/installed'.
grep -q ":/var/db/kiss/installed/" "$mak_dir/$pid-c" ||
choice_auto=1
if [ "$KISS_CHOICE" != 0 ] &&
[ "$choice_auto" = 1 ] &&
[ -s "$mak_dir/$pid-c" ]; then
# This is a novel way of offering an "alternatives" system.
# It is entirely dynamic and all "choices" are created and
# destroyed on the fly.
# #
# When a conflict is found between two packages, the file # All file conflicts are installed to the choices directory
# is moved to a directory called "choices" and its name # rather than their original destination. The package's
# changed to store its parent package and its intended # manifest is updated to reflect this.
# location.
# #
# The package's manifest is then updated to reflect this # Swapping between choices just moves the locations of two
# new location. # files around. The file in the system is copied to the
# # choices directory and the choice is moved to the system
# The 'kiss alternatives' command parses this directory and # (overwriting the remaining prior copy)
# offers you the CHOICE of *swapping* entries in this
# directory for those on the filesystem.
#
# The alternatives command does the same thing we do here,
# it rewrites manifests and moves files around to make
# this work.
#
# Pretty nifty huh?
while IFS=: read -r _ con; do while IFS=: read -r _ con; do
printf 'Found conflict %s\n' "$con" printf 'Found conflict %s\n' "$con"
@ -796,18 +769,18 @@ pkg_conflicts() {
# Construct the file name of the "db" entry of the # Construct the file name of the "db" entry of the
# conflicting file. (pkg_name>usr>bin>ls) # conflicting file. (pkg_name>usr>bin>ls)
con_name=$(printf %s "$con" | sed 's|/|>|g') con_name=$(printf %s "$pkg$con" | sed 's|/|>|g')
# Move the conflicting file to the choices directory # Move the conflicting file to the choices directory
# and name it according to the format above. # and name it according to the format above.
mv -f "$tar_dir/$pkg/$con" \ mv -f "$tar_dir/$pkg/$con" \
"$tar_dir/$pkg/$cho_dir/$pkg$con_name" 2>/dev/null || { "$tar_dir/$pkg/$cho_dir/$con_name" 2>/dev/null || {
log "File must be in ${con%/*} and not a symlink to it" log "File must be in ${con%/*} and not a symlink to it"
log "This usually occurs when a binary is installed to" log "This can occur when a binary is installed to"
log "/sbin instead of /usr/bin (example)" log "/sbin instead of /usr/bin (example)"
log "Before this package can be used as an alternative," log "Before this file can be used as an alternative,"
log "this must be fixed in $pkg. Contact the maintainer" log "this must be fixed in $pkg. Contact the maintainer"
die "by finding their details via 'kiss-maintainer'" "" "!>" die "by finding their details via kiss-maintainer" "" "!>"
} }
done < "$mak_dir/$pid-c" done < "$mak_dir/$pid-c"