From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 6B02113835A for ; Thu, 11 Mar 2021 14:08:41 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A0FBBE0BC5; Thu, 11 Mar 2021 14:08:40 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 887D3E0BC5 for ; Thu, 11 Mar 2021 14:08:40 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 87029340EB2 for ; Thu, 11 Mar 2021 14:08:39 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 2718D58C for ; Thu, 11 Mar 2021 14:08:38 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: <1615471712.138797c63271bb63f9769964a42a9a4307c8bb17.mgorny@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/ X-VCS-Repository: repo/gentoo X-VCS-Files: eclass/kernel-install.eclass X-VCS-Directories: eclass/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: 138797c63271bb63f9769964a42a9a4307c8bb17 X-VCS-Branch: master Date: Thu, 11 Mar 2021 14:08:38 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 2743d56a-514b-43db-b8b3-842303de97a8 X-Archives-Hash: faf46e35dc784d273dd0f8f4e173de6c commit: 138797c63271bb63f9769964a42a9a4307c8bb17 Author: Michał Górny gentoo org> AuthorDate: Thu Mar 11 13:19:44 2021 +0000 Commit: Michał Górny gentoo org> CommitDate: Thu Mar 11 14:08:32 2021 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=138797c6 kernel-install.eclass: Refactor /usr/src/linux check to function Refactor the check whether /usr/src/linux should be updated to a separate function, to improve readability. Signed-off-by: Michał Górny gentoo.org> eclass/kernel-install.eclass | 69 +++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass index e3357cda0fd..107a526c328 100644 --- a/eclass/kernel-install.eclass +++ b/eclass/kernel-install.eclass @@ -76,6 +76,45 @@ BDEPEND=" x86? ( app-emulation/qemu[qemu_softmmu_targets_i386] ) )" +# @FUNCTION: kernel-install_can_update_symlink +# @USAGE: +# @DESCRIPTION: +# Determine whether the symlink at (full path) should be +# updated. Returns 0 if it should, 1 to leave as-is. +kernel-install_can_update_symlink() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${#} -eq 1 ]] || die "${FUNCNAME}: invalid arguments" + local target=${1} + + # if the symlink does not exist or is broken, update + [[ ! -e ${target} ]] && return 0 + + local symlink_target=$(readlink "${target}") + # the symlink target should start with the same basename as target + # (e.g. "linux-*") + [[ ${symlink_target} != ${target##*/}-* ]] && return 1 + + # try to establish the kernel version from symlink target + local symlink_ver=${symlink_target#${target##*/}-} + # strip KV_LOCALVERSION, we want to update the old kernels not using + # KV_LOCALVERSION suffix and the new kernels using it + symlink_ver=${symlink_ver%${KV_LOCALVERSION}} + + # if ${symlink_ver} contains anything but numbers (e.g. an extra + # suffix), it's not our kernel, so leave it alone + [[ -n ${symlink_ver//[0-9.]/} ]] && return 1 + + local symlink_pkg=${CATEGORY}/${PN}-${symlink_ver} + # if the current target is either being replaced, or still + # installed (probably depclean candidate), update the symlink + has "${symlink_ver}" ${REPLACING_VERSIONS} && return 0 + has_version -r "~${symlink_pkg}" && return 0 + + # otherwise it could be another kernel package, so leave it alone + return 1 +} + # @FUNCTION: kernel-install_update_symlink # @USAGE: # @DESCRIPTION: @@ -89,35 +128,13 @@ kernel-install_update_symlink() { local target=${1} local version=${2} - if [[ ! -e ${target} ]]; then - ebegin "Creating ${target} symlink" + if kernel-install_can_update_symlink "${target}"; then + ebegin "Updating ${target} symlink" ln -f -n -s "${target##*/}-${version}" "${target}" eend ${?} else - local symlink_target=$(readlink "${target}") - local symlink_ver=${symlink_target#${target##*/}-} - local updated= - symlink_ver=${symlink_ver%${KV_LOCALVERSION}} - if [[ ${symlink_target} == ${target##*/}-* && \ - -z ${symlink_ver//[0-9.]/} ]] - then - local symlink_pkg=${CATEGORY}/${PN}-${symlink_ver} - # if the current target is either being replaced, or still - # installed (probably depclean candidate), update the symlink - if has "${symlink_ver}" ${REPLACING_VERSIONS} || - has_version -r "~${symlink_pkg}" - then - ebegin "Updating ${target} symlink" - ln -f -n -s "${target##*/}-${version}" "${target}" - eend ${?} - updated=1 - fi - fi - - if [[ ! ${updated} ]]; then - elog "${target} points at another kernel, leaving it as-is." - elog "Please use 'eselect kernel' to update it when desired." - fi + elog "${target} points at another kernel, leaving it as-is." + elog "Please use 'eselect kernel' to update it when desired." fi }