Skip to content

Commit

Permalink
Make cachedir relative to installroot
Browse files Browse the repository at this point in the history
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
  • Loading branch information
evan-goode committed Jan 8, 2024
1 parent 6fa8618 commit 1fb6350
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/misc/installroot.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions libdnf5/base/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1fb6350

Please sign in to comment.