Skip to content

Commit 416c6f1

Browse files
jrohelm-blaha
authored andcommitted
[context] Make support for libdnf5 conf drop-in, overrides conditional
In previous commits, support for libdnf5 drop-in configuration directories and directories with repositories configuration overrides was added to the context part of libdnf. This changes the behavior of libdnf. Therefore, the new behavior can now be turned off during library compilation. Added build options: ENABLE_DNF5_CONF_DROP_IN - support for drop-in directories ENABLE_DNF5_CONF_REPOS_OVERRIDE - support for repositories overrides
1 parent 4b5742e commit 416c6f1

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ option(WITH_GTKDOC "Enables libdnf GTK-Doc HTML documentation" ON)
3131
option(WITH_HTML "Enables hawkey HTML generation" ON)
3232
option(WITH_MAN "Enables hawkey man page generation" ON)
3333
option(WITH_ZCHUNK "Build with zchunk support" ON)
34+
option(ENABLE_DNF5_CONF_DROP_IN "Build with support for libdnf5 drop-in configuration directories?" ON)
35+
option(ENABLE_DNF5_CONF_REPOS_OVERRIDE "Build with support for libdnf5 repository configuration overrides?" ON)
3436
option(ENABLE_RHSM_SUPPORT "Build with Red Hat Subscription Manager support?" OFF)
3537
option(ENABLE_SOLV_URPMREORDER "Build with support for URPM-like solution reordering?" OFF)
3638
option(WITH_TESTS "Enables unit tests" ON)
@@ -132,6 +134,16 @@ add_definitions(-DG_LOG_DOMAIN="libdnf")
132134
# tests
133135
add_definitions(-DTESTDATADIR="${CMAKE_SOURCE_DIR}/data/tests")
134136

137+
# Use libdnf5 drop-in configuration directories including distribution configuration.
138+
if(ENABLE_DNF5_CONF_DROP_IN)
139+
add_definitions(-DDNF5_CONF_DROP_IN)
140+
endif()
141+
142+
# Use libdnf5 repository overrides. Save repo conf chnges to "99-config_manager.repo" override.
143+
if(ENABLE_DNF5_CONF_REPOS_OVERRIDE)
144+
add_definitions(-DDNF5_CONF_REPOS_OVERRIDE)
145+
endif()
146+
135147
# librhsm
136148
if(ENABLE_RHSM_SUPPORT)
137149
add_definitions(-DRHSM_SUPPORT)

libdnf/dnf-context.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4037,6 +4037,7 @@ libdnf::ConfigMain & getGlobalMainConfig(bool canReadConfigFile)
40374037

40384038
const std::string cfgPath{globalMainConfig->config_file_path().getValue()};
40394039
try {
4040+
#ifdef DNF5_CONF_DROP_IN
40404041
std::string conf_dir_path{CONF_DIR};
40414042
std::string dist_conf_dir_path{DISTRIBUTION_CONF_DIR};
40424043

@@ -4057,6 +4058,7 @@ libdnf::ConfigMain & getGlobalMainConfig(bool canReadConfigFile)
40574058
parser.read(path);
40584059
load_from_parser(parser, path);
40594060
}
4061+
#endif
40604062

40614063
// Finally, if a user configuration filename is defined or the file exists in the default location,
40624064
// it will be loaded.

libdnf/dnf-repo.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262
#include "utils/url-encode.hpp"
6363
#include "utils/utils.hpp"
6464

65+
#ifdef DNF5_CONF_REPOS_OVERRIDE
6566
#include <map>
67+
#endif
6668
#include <set>
6769
#include <string>
6870
#include <vector>
@@ -88,7 +90,9 @@ typedef struct
8890
LrHandle *repo_handle;
8991
LrResult *repo_result;
9092
LrUrlVars *urlvars;
93+
#ifdef DNF5_CONF_REPOS_OVERRIDE
9194
std::map<std::string, std::string> *config_changes; // dnf_repo_set_data, dnf_repo_commit
95+
#endif
9296
bool unit_test_mode; /* ugly hack for unit tests */
9397
} DnfRepoPrivate;
9498

@@ -124,8 +128,10 @@ dnf_repo_finalize(GObject *object)
124128
if (priv->context != NULL)
125129
g_object_remove_weak_pointer(G_OBJECT(priv->context),
126130
(void **) &priv->context);
131+
#ifdef DNF5_CONF_REPOS_OVERRIDE
127132
if (priv->config_changes)
128133
delete priv->config_changes;
134+
#endif
129135

130136
G_OBJECT_CLASS(dnf_repo_parent_class)->finalize(object);
131137
}
@@ -930,6 +936,7 @@ dnf_repo_conf_from_gkeyfile(DnfRepo *repo, const char *repoId, GKeyFile *gkeyFil
930936
}
931937
}
932938

939+
#ifdef DNF5_CONF_REPOS_OVERRIDE
933940
/* Loads repository configuration overrides */
934941
static void
935942
dnf_repo_conf_load_overrides(DnfRepo *repo, const char *repoId)
@@ -987,7 +994,7 @@ dnf_repo_conf_load_overrides(DnfRepo *repo, const char *repoId)
987994
}
988995
}
989996
}
990-
997+
#endif
991998

992999
static void
9931000
dnf_repo_apply_setopts(libdnf::ConfigRepo &config, const char *repoId)
@@ -1032,7 +1039,9 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, gboolean reloadFromGKeyFile, GError **e
10321039
// Reload repository configuration from keyfile.
10331040
if (reloadFromGKeyFile) {
10341041
dnf_repo_conf_from_gkeyfile(repo, repoId, priv->keyfile);
1042+
#ifdef DNF5_CONF_REPOS_OVERRIDE
10351043
dnf_repo_conf_load_overrides(repo, repoId);
1044+
#endif
10361045
dnf_repo_apply_setopts(*conf, repoId);
10371046
}
10381047

@@ -1314,7 +1323,9 @@ dnf_repo_setup(DnfRepo *repo, GError **error) try
13141323

13151324
auto conf = priv->repo->getConfig();
13161325
dnf_repo_conf_from_gkeyfile(repo, repoId, priv->keyfile);
1326+
#ifdef DNF5_CONF_REPOS_OVERRIDE
13171327
dnf_repo_conf_load_overrides(repo, repoId);
1328+
#endif
13181329
dnf_repo_apply_setopts(*conf, repoId);
13191330

13201331
auto sslverify = conf->sslverify().getValue();
@@ -2109,18 +2120,20 @@ dnf_repo_set_data(DnfRepo *repo,
21092120
{
21102121
DnfRepoPrivate *priv = GET_PRIVATE(repo);
21112122

2123+
#ifdef DNF5_CONF_REPOS_OVERRIDE
21122124
// we note the changes
21132125
// dnf_repo_commit writes them to the override configuration file
21142126
if (!priv->config_changes) {
21152127
priv->config_changes = new std::map<std::string, std::string>;
21162128
}
21172129
(*priv->config_changes)[parameter] = value;
2130+
#endif
21182131

21192132
g_key_file_set_string(priv->keyfile, priv->repo->getId().c_str(), parameter, value);
21202133
return TRUE;
21212134
} CATCH_TO_GERROR(FALSE)
21222135

2123-
2136+
#ifdef DNF5_CONF_REPOS_OVERRIDE
21242137
static std::string
21252138
get_repos_config_override_dir_path(DnfRepo *repo)
21262139
{
@@ -2148,6 +2161,7 @@ modify_config(libdnf::ConfigParser & parser, const std::string & section_id, con
21482161
parser.setValue(section_id, key_val.first, key_val.second, "");
21492162
}
21502163
}
2164+
#endif
21512165

21522166
/**
21532167
* dnf_repo_commit:
@@ -2175,6 +2189,7 @@ dnf_repo_commit(DnfRepo *repo, GError **error) try
21752189
return FALSE;
21762190
}
21772191

2192+
#ifdef DNF5_CONF_REPOS_OVERRIDE
21782193
constexpr const char * REPOS_OVERRIDE_CFG_HEADER =
21792194
"# Generated by libdnf.\n# Do not modify this file manually.\n";
21802195
const std::string CFG_MANAGER_REPOS_OVERRIDE_FILENAME = "99-config_manager.repo";
@@ -2209,8 +2224,16 @@ dnf_repo_commit(DnfRepo *repo, GError **error) try
22092224
delete priv->config_changes;
22102225
priv->config_changes = nullptr;
22112226
}
2212-
22132227
return TRUE;
2228+
2229+
#else
2230+
2231+
/* dump updated file to disk */
2232+
data = g_key_file_to_data(priv->keyfile, NULL, error);
2233+
if (data == NULL)
2234+
return FALSE;
2235+
return g_file_set_contents(priv->filename, data, -1, error);
2236+
#endif
22142237
} CATCH_TO_GERROR(FALSE)
22152238

22162239
/**

0 commit comments

Comments
 (0)