Skip to content

Commit

Permalink
transaction: Don't remove cache when no inbound action
Browse files Browse the repository at this point in the history
When the `keepcache` option is turned off, the packages downloaded during a previous command should still be preserved until a subsequent successful transaction that involves inbound actions such as installation or upgrading. This assumption is based on the idea that these packages were downloaded for this purpose.

As a result, temporary packages are retained even across transactions that do not involve any inbound actions.

This feature is also valuable in cases where a previous transaction downloaded a substantial amount of data but did not complete correctly. In such instances, we want to rectify the system state by removing problematic packages without losing our cached data.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2237883
  • Loading branch information
jan-kolarik committed Sep 20, 2023
1 parent c0bdd92 commit eb19d9a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion libdnf5/base/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,15 @@ static void process_scriptlets_output(int fd, Logger * logger) {
close(fd);
}

static bool contains_any_inbound_package(std::vector<TransactionPackage> & packages) {
for (const auto & package : packages) {
if (transaction_item_action_is_inbound(package.get_action())) {
return true;
}
}
return false;
}

Transaction::TransactionRunResult Transaction::Impl::test() {
return this->_run(std::make_unique<libdnf5::rpm::TransactionCallbacks>(), "", std::nullopt, "", true);
}
Expand Down Expand Up @@ -869,7 +878,10 @@ Transaction::TransactionRunResult Transaction::Impl::_run(

if (ret == 0) {
// removes any temporarily stored packages from the system
if (!config.get_keepcache_option().get_value()) {
// only if any inbound action takes place
auto keepcache = config.get_keepcache_option().get_value();
auto any_inbound_action_present = contains_any_inbound_package(packages);
if (!keepcache && any_inbound_action_present) {
libdnf5::repo::TempFilesMemory temp_files_memory(config.get_cachedir_option().get_value());
auto temp_files = temp_files_memory.get_files();
for (auto & file : temp_files) {
Expand Down

0 comments on commit eb19d9a

Please sign in to comment.