update: safe leaf_update_package_datebase

This commit is contained in:
2026-01-17 16:18:42 -05:00
parent 30fed4b734
commit 2fc05ba7ea

17
leaf
View File

@@ -548,18 +548,25 @@ leaf_conffile_is_unmodified() {
} }
leaf_update_package_database() { leaf_update_package_database() {
local _item="$(echo "$2" | awk 'BEGIN{FS="/";OFS="\\/"}{print $1,$2}')" local action=$1 atom=$2 db="${INSTALLED_PACKAGES}"
case $1 in local tmp="${db}.tmp.$$"
case "$action" in
add) add)
sed -i "/${_item}/d" "${INSTALLED_PACKAGES}" { [ -f "$db" ] && grep -Fvx -- "$atom" "$db" || :; printf '%s\n' "$atom"; } >"$tmp" &&
echo "$2" >> ${INSTALLED_PACKAGES} mv -f -- "$tmp" "$db"
;; ;;
delete) delete)
sed -i "/${_item}/d" "${INSTALLED_PACKAGES}" grep -Fvx -- "$atom" "$db" >"$tmp" &&
mv -f -- "$tmp" "$db"
;;
*)
leaf_error "unknown operation leaf_update_package_database ${action}."
;; ;;
esac esac
} }
leaf_update_environment() { leaf_update_environment() {
ldconfig ldconfig
[ ! -r /etc/profile ] || source /etc/profile [ ! -r /etc/profile ] || source /etc/profile