From 1fb635058bfca6f009ca6489ca7f3c02d588f50c Mon Sep 17 00:00:00 2001 From: Evan Goode Date: Mon, 8 Jan 2024 18:30:49 +0000 Subject: [PATCH] Make cachedir relative to installroot Like `logdir`, the `cachedir` configuration option should be treated as relative to the installroot, unless it is specified on the command line via --setopt=cachedir=/path/to/cachedir. This is the behavior of the cachedir with DNF 4. Currently, the host cache directory is used by default, conflicting with what our docs say (man 7 dnf5-installroot): "cachedir, log files, releasever, and gpgkey are taken from or stored in the installroot." After this change, the default cachedir is $installroot/var/cache/libdnf5, which is consistent with the docs. For https://bugzilla.redhat.com/show_bug.cgi?id=2256945 --- doc/misc/installroot.7.rst | 1 + libdnf5/base/base.cpp | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/misc/installroot.7.rst b/doc/misc/installroot.7.rst index 1c087d30e..a18420bb2 100644 --- a/doc/misc/installroot.7.rst +++ b/doc/misc/installroot.7.rst @@ -43,6 +43,7 @@ will be used. Note: When a path is specified within a command line argument (``--config=CONFIG_FILE_PATH`` in case of `configuration` file, ``--setopt=reposdir=/path/to/repodir`` for `reposdir`, +``--setopt=cachedir=/path/to/cachedir`` for `cachedir`, ``--setopt=logdir=/path/to/logdir`` for `logdir`, or ``--setopt=varsdir=/paths/to/varsdir`` for `vars`), then this path is always relative to the host with no exceptions. `pluginpath` and `pluginconfpath` are diff --git a/libdnf5/base/base.cpp b/libdnf5/base/base.cpp index 1b2e9ff79..1ea72e385 100644 --- a/libdnf5/base/base.cpp +++ b/libdnf5/base/base.cpp @@ -165,12 +165,17 @@ void Base::setup() { vars_installroot = config.get_installroot_option().get_value(); } } - // Unless the logdir is specified on the command line, logdir should be - // relative to the installroot + // Unless the cachedir or logdir are specified on the command line, they + // should be relative to the installroot if (config.get_logdir_option().get_priority() < Option::Priority::COMMANDLINE) { const std::filesystem::path logdir_path{config.get_logdir_option().get_value()}; - const auto full_path = (installroot_path / logdir_path.relative_path()).string(); - config.get_logdir_option().set(Option::Priority::INSTALLROOT, full_path); + const auto full_path = installroot_path / logdir_path.relative_path(); + config.get_logdir_option().set(Option::Priority::INSTALLROOT, full_path.string()); + } + if (config.get_cachedir_option().get_priority() < Option::Priority::COMMANDLINE) { + const std::filesystem::path cachedir_path{config.get_cachedir_option().get_value()}; + const auto full_path = installroot_path / cachedir_path.relative_path(); + config.get_cachedir_option().set(Option::Priority::INSTALLROOT, full_path.string()); } load_plugins();