From d203ba3bf796c9999e8a819b1397d64603e17e04 Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Mon, 20 May 2019 01:47:55 +0200 Subject: [PATCH] savedconfig.eclass: Make save_config() re-use configuration file scheme used by restore_config(). Fixes: https://bugs.gentoo.org/686348 Signed-off-by: Arfrever Frehtes Taifersar Arahesis --- eclass/savedconfig.eclass | 42 ++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/eclass/savedconfig.eclass b/eclass/savedconfig.eclass index 1e9ac6c80b4..a518125b29f 100644 --- a/eclass/savedconfig.eclass +++ b/eclass/savedconfig.eclass @@ -1,4 +1,4 @@ -# Copyright 1999-2011 Gentoo Foundation +# Copyright 2007-2019 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: savedconfig.eclass @@ -33,6 +33,13 @@ inherit portability IUSE="savedconfig" +# @ECLASS-VARIABLE: _SAVEDCONFIG_CONFIGURATION_FILE +# @DEFAULT_UNSET +# @INTERNAL +# @DESCRIPTION: +# Path of configuration file, relative to /etc/portage/savedconfig, +# restored by restore_config() and saved by save_config(). + # @FUNCTION: save_config # @USAGE: # @DESCRIPTION: @@ -49,20 +56,26 @@ save_config() { # Be lazy in our EAPI compat : ${ED:=${D}} - local dest="/etc/portage/savedconfig/${CATEGORY}" + local configfile + if [[ -n ${_SAVEDCONFIG_CONFIGURATION_FILE} ]]; then + configfile="/etc/portage/savedconfig/${_SAVEDCONFIG_CONFIGURATION_FILE}" + else + configfile="/etc/portage/savedconfig/${CATEGORY}/${PF}" + fi + if [[ $# -eq 1 && -f $1 ]] ; then - # Just one file, so have the ${PF} be that config file - dodir "${dest}" - cp "$@" "${ED}/${dest}/${PF}" || die "failed to save $*" + # Just one file, so have the ${configfile} be that config file + dodir "${configfile%/*}" + cp "$@" "${ED}/${configfile}" || die "failed to save $*" else - # A dir, or multiple files, so have the ${PF} be a dir + # A dir, or multiple files, so have the ${configfile} be a dir # with all the saved stuff below it - dodir "${dest}/${PF}" - treecopy "$@" "${ED}/${dest}/${PF}" || die "failed to save $*" + dodir "${configfile}" + treecopy "$@" "${ED}/${configfile}" || die "failed to save $*" fi elog "Your configuration for ${CATEGORY}/${PF} has been saved in " - elog "/etc/portage/savedconfig/${CATEGORY}/${PF} for your editing pleasure." + elog "\"${configfile}\" for your editing pleasure." elog "You can edit these files by hand and remerge this package with" elog "USE=savedconfig to customise the configuration." elog "You can rename this file/directory to one of the following for" @@ -74,7 +87,7 @@ save_config() { # @FUNCTION: restore_config # @USAGE: # @DESCRIPTION: -# Restores the configuation saved ebuild previously potentially with user edits. +# Restores the configuration saved ebuild previously potentially with user edits. # You can restore a single file or a whole bunch, just make sure you call # restore_config with all of the files to restore at the same time. # @@ -99,16 +112,17 @@ restore_config() { use savedconfig || return local found check configfile - local base=${PORTAGE_CONFIGROOT}/etc/portage/savedconfig + local base=${PORTAGE_CONFIGROOT%/}/etc/portage/savedconfig for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do configfile=${base}/${CTARGET}/${check} [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check} [[ -r ${configfile} ]] || configfile=${base}/${check} einfo "Checking existence of ${configfile} ..." if [[ -r "${configfile}" ]]; then - einfo "found ${configfile}" - found=${configfile}; - break; + einfo "Found ${configfile}" + found=${configfile} + _SAVEDCONFIG_CONFIGURATION_FILE=${configfile#${base}/} + break fi done if [[ -f ${found} ]]; then -- 2.21.0