Gentoo Archives: gentoo-dev

From: Thomas Deutschmann <whissi@g.o>
To: gentoo-dev@l.g.o
Cc: Arfrever@××××××.Org, base-system@g.o
Subject: [gentoo-dev] [PATCH 1/3] savedconfig.eclass: Make save_config() re-use configuration file scheme used by restore_config()
Date: Sat, 03 Aug 2019 13:18:41
Message-Id: 20190803131759.37037-1-whissi@gentoo.org
1 From: Arfrever Frehtes Taifersar Arahesis <Arfrever@××××××.Org>
2
3 Fixes: https://bugs.gentoo.org/686348
4 Signed-off-by: Arfrever Frehtes Taifersar Arahesis <Arfrever@××××××.Org>
5 Signed-off-by: Thomas Deutschmann <whissi@g.o>
6 ---
7 eclass/savedconfig.eclass | 40 ++++++++++++++++++++++++++-------------
8 1 file changed, 27 insertions(+), 13 deletions(-)
9
10 diff --git a/eclass/savedconfig.eclass b/eclass/savedconfig.eclass
11 index e0b1953d56d0..b96f55d4c27c 100644
12 --- a/eclass/savedconfig.eclass
13 +++ b/eclass/savedconfig.eclass
14 @@ -38,6 +38,13 @@ case ${EAPI} in
15 *) die "EAPI=${EAPI:-0} is not supported" ;;
16 esac
17
18 +# @ECLASS-VARIABLE: _SAVEDCONFIG_CONFIGURATION_FILE
19 +# @DEFAULT_UNSET
20 +# @INTERNAL
21 +# @DESCRIPTION:
22 +# Path of configuration file, relative to /etc/portage/savedconfig,
23 +# restored by restore_config() and saved by save_config().
24 +
25 # @FUNCTION: save_config
26 # @USAGE: <config files to save>
27 # @DESCRIPTION:
28 @@ -51,20 +58,26 @@ save_config() {
29 fi
30 [[ $# -eq 0 ]] && die "Usage: save_config <files>"
31
32 - local dest="/etc/portage/savedconfig/${CATEGORY}"
33 + local configfile
34 + if [[ -n ${_SAVEDCONFIG_CONFIGURATION_FILE} ]] ; then
35 + configfile="/etc/portage/savedconfig/${_SAVEDCONFIG_CONFIGURATION_FILE}"
36 + else
37 + configfile="/etc/portage/savedconfig/${CATEGORY}/${PF}"
38 + fi
39 +
40 if [[ $# -eq 1 && -f $1 ]] ; then
41 - # Just one file, so have the ${PF} be that config file
42 - dodir "${dest}"
43 - cp "$@" "${ED%/}/${dest}/${PF}" || die "failed to save $*"
44 + # Just one file, so have the ${configfile} be that config file
45 + dodir "${configfile%/*}"
46 + cp "$@" "${ED%/}/${configfile}" || die "failed to save $*"
47 else
48 - # A dir, or multiple files, so have the ${PF} be a dir
49 + # A dir, or multiple files, so have the ${configfile} be a dir
50 # with all the saved stuff below it
51 - dodir "${dest}/${PF}"
52 - treecopy "$@" "${ED%/}/${dest}/${PF}" || die "failed to save $*"
53 + dodir "${configfile}"
54 + treecopy "$@" "${ED%/}/${configfile}" || die "failed to save $*"
55 fi
56
57 elog "Your configuration for ${CATEGORY}/${PF} has been saved in "
58 - elog "/etc/portage/savedconfig/${CATEGORY}/${PF} for your editing pleasure."
59 + elog "\"${configfile}\" for your editing pleasure."
60 elog "You can edit these files by hand and remerge this package with"
61 elog "USE=savedconfig to customise the configuration."
62 elog "You can rename this file/directory to one of the following for"
63 @@ -76,7 +89,7 @@ save_config() {
64 # @FUNCTION: restore_config
65 # @USAGE: <config files to restore>
66 # @DESCRIPTION:
67 -# Restores the configuation saved ebuild previously potentially with user edits.
68 +# Restores the configuration saved ebuild previously potentially with user edits.
69 # You can restore a single file or a whole bunch, just make sure you call
70 # restore_config with all of the files to restore at the same time.
71 #
72 @@ -107,10 +120,11 @@ restore_config() {
73 [[ -r ${configfile} ]] || configfile=${base}/${CHOST}/${check}
74 [[ -r ${configfile} ]] || configfile=${base}/${check}
75 einfo "Checking existence of ${configfile} ..."
76 - if [[ -r "${configfile}" ]]; then
77 - einfo "found ${configfile}"
78 - found=${configfile};
79 - break;
80 + if [[ -r "${configfile}" ]] ; then
81 + einfo "Found \"${configfile}\""
82 + found=${configfile}
83 + _SAVEDCONFIG_CONFIGURATION_FILE=${configfile#${base}/}
84 + break
85 fi
86 done
87 if [[ -f ${found} ]]; then
88 --
89 2.22.0

Replies