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

Replies