kiss: make function for pkg owner

This commit is contained in:
Dylan Araps 2020-09-26 08:08:10 +03:00
parent 1859cb34b2
commit 93dc3a1fcd
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 24 additions and 31 deletions

55
kiss
View File

@ -125,6 +125,13 @@ sh256() {
printf '%s\n' "${hash%% *}" printf '%s\n' "${hash%% *}"
} }
pkg_owner() {
pkg_owner=$(grep -lFx "$@") && {
pkg_owner=${pkg_owner%/*}
pkg_owner=${pkg_owner##*/}
}
}
pkg_lint() { pkg_lint() {
pkg_find "$1" pkg_find "$1"
cd "$repo_dir" cd "$repo_dir"
@ -469,22 +476,20 @@ pkg_fixdeps() {
esac || continue esac || continue
# Figure out which package owns the file. # Figure out which package owns the file.
dep=$(grep -lFx "${PWD#"$KISS_ROOT"}/${dep##*/}" "$@") pkg_owner "${PWD#"$KISS_ROOT"}/${dep##*/}" "$@" ||
dep=${dep%/*} continue
dep=${dep##*/}
case $dep in case $pkg_owner in
gcc | \ gcc | \
llvm | \ llvm | \
"$pkg" | \ "$pkg" | \
"${pkg%%-bin}" | \ "${pkg%%-bin}" | \
"${pkg%%-git}" | \ "${pkg%%-git}" )
'')
# Do nothing. # Do nothing.
;; ;;
*) *)
printf '%s\n' "$dep" printf '%s\n' "$pkg_owner"
;; ;;
esac esac
done ||: done ||:
@ -887,31 +892,19 @@ pkg_swap() {
# Figure out which package owns the file we are going to swap for # 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 # another package's. Print the full path to the manifest file which
# contains the match to our search. # contains the match to our search.
pkg_owns=$( set +f
set +f pkg_owner "$2" "$sys_db/"*/manifest ||
grep -lFx "$2" "$sys_db/"*/manifest die "File '$2' exists on filesystem but isn't owned"
) ||: set -f
# Extract the package name from the path above. # Convert the current owner to an alternative and rewrite its
pkg_owns=${pkg_owns%/*} # manifest file to reflect this.
pkg_owns=${pkg_owns##*/} cp -Pf "$KISS_ROOT/$2" "$pkg_owner>${alt#*>}"
case $pkg_owns in find_replace \
'') "$2" \
die "File '$2' exists on filesystem but isn't owned" "${PWD#"$KISS_ROOT"}/$pkg_owner>${alt#*>}" \
;; "../installed/$pkg_owner/manifest"
*)
# Convert the current owner to an alternative and rewrite its
# manifest file to reflect this.
cp -Pf "$KISS_ROOT/$2" "$pkg_owns>${alt#*>}"
find_replace \
"$2" \
"${PWD#"$KISS_ROOT"}/$pkg_owns>${alt#*>}" \
"../installed/$pkg_owns/manifest"
;;
esac
fi fi
# Convert the desired alternative to a real file and rewrite the manifest # Convert the desired alternative to a real file and rewrite the manifest
@ -924,7 +917,7 @@ pkg_swap() {
"$2" \ "$2" \
"../installed/$1/manifest" "../installed/$1/manifest"
printf '%s is now provided by %s (was %s)\n' "$2" "$1" "$pkg_owns" printf '%s is now provided by %s (was %s)\n' "$2" "$1" "$pkg_owner"
} }
pkg_install_files() { pkg_install_files() {