Skip to content

Commit 3889d69

Browse files
jrohelConan-Kudo
authored andcommitted
[context] Support config file option "installonlypkgs"
The "installonlypkgs" option was ignored. Instead, a hard-coded list of installation packages was always used. It now works as in DNF. = changelog = msg: Support main config file option "installonlypkgs". Changes behaviour of microdnf and PackageKit. type: bugfix
1 parent 9cc4bf4 commit 3889d69

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

libdnf/dnf-context.cpp

+38-9
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ typedef struct
137137
{
138138
gchar **repos_dir;
139139
gchar **vars_dir;
140+
gchar **installonlypkgs;
140141
gchar *base_arch;
141142
gchar *release_ver;
142143
gchar *platform_module;
@@ -220,6 +221,7 @@ dnf_context_finalize(GObject *object)
220221

221222
g_strfreev(priv->repos_dir);
222223
g_strfreev(priv->vars_dir);
224+
g_strfreev(priv->installonlypkgs);
223225
g_free(priv->base_arch);
224226
g_free(priv->release_ver);
225227
g_free(priv->platform_module);
@@ -1092,20 +1094,47 @@ dnf_context_get_cache_age(DnfContext *context)
10921094
*
10931095
* Gets the packages that are allowed to be installed more than once.
10941096
*
1097+
* The return value is valid until the value of the global configuration "installonlypkgs" changes.
1098+
* E.g. using dnf_conf_main_set_option() or dnf_conf_add_setopt().
1099+
*
10951100
* Returns: (transfer none): array of package names
10961101
*/
10971102
const gchar **
10981103
dnf_context_get_installonly_pkgs(DnfContext *context)
10991104
{
1100-
static const gchar *installonly_pkgs[] = {
1101-
"kernel",
1102-
"kernel-PAE",
1103-
"installonlypkg(kernel)",
1104-
"installonlypkg(kernel-module)",
1105-
"installonlypkg(vm)",
1106-
"multiversion(kernel)",
1107-
NULL };
1108-
return installonly_pkgs;
1105+
DnfContextPrivate *priv = GET_PRIVATE(context);
1106+
auto & mainConf = libdnf::getGlobalMainConfig();
1107+
auto & packages = mainConf.installonlypkgs().getValue();
1108+
1109+
// If "installonlypkgs" is not initialized (first run), set "differs" to true.
1110+
bool differs = !priv->installonlypkgs;
1111+
1112+
// Test if they are not different.
1113+
if (!differs) {
1114+
size_t i = 0;
1115+
while (i < packages.size()) {
1116+
if (!priv->installonlypkgs[i] || packages[i].compare(priv->installonlypkgs[i]) != 0) {
1117+
differs = true;
1118+
break;
1119+
}
1120+
++i;
1121+
}
1122+
if (priv->installonlypkgs[i]) {
1123+
differs = true;
1124+
}
1125+
}
1126+
1127+
// Re-initialize "installonlypkgs" only if it differs from the values in mainConf.
1128+
if (differs) {
1129+
g_strfreev(priv->installonlypkgs);
1130+
priv->installonlypkgs = g_new0(gchar*, packages.size() + 1);
1131+
1132+
for (size_t i = 0; i < packages.size(); ++i) {
1133+
priv->installonlypkgs[i] = g_strdup(packages[i].c_str());
1134+
}
1135+
}
1136+
1137+
return const_cast<const gchar **>(priv->installonlypkgs);
11091138
}
11101139

11111140
/**

0 commit comments

Comments
 (0)