@@ -137,6 +137,7 @@ typedef struct
137
137
{
138
138
gchar * * repos_dir ;
139
139
gchar * * vars_dir ;
140
+ gchar * * installonlypkgs ;
140
141
gchar * base_arch ;
141
142
gchar * release_ver ;
142
143
gchar * platform_module ;
@@ -220,6 +221,7 @@ dnf_context_finalize(GObject *object)
220
221
221
222
g_strfreev (priv -> repos_dir );
222
223
g_strfreev (priv -> vars_dir );
224
+ g_strfreev (priv -> installonlypkgs );
223
225
g_free (priv -> base_arch );
224
226
g_free (priv -> release_ver );
225
227
g_free (priv -> platform_module );
@@ -1092,20 +1094,47 @@ dnf_context_get_cache_age(DnfContext *context)
1092
1094
*
1093
1095
* Gets the packages that are allowed to be installed more than once.
1094
1096
*
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
+ *
1095
1100
* Returns: (transfer none): array of package names
1096
1101
*/
1097
1102
const gchar * *
1098
1103
dnf_context_get_installonly_pkgs (DnfContext * context )
1099
1104
{
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 );
1109
1138
}
1110
1139
1111
1140
/**
0 commit comments