Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't drop cached packages when only removing packages (RhBug:2237883) #885

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/libdnf5/base/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ class Transaction {
/// To watch progress or trigger actions during specific transactions events,
/// setup the `callbacks` object.
///
/// After a successful transaction, any temporarily downloaded packages are removed
/// if the 'keepcache' option is set to 'false' and the transaction involved an inbound action.
/// Otherwise, the packages are preserved on the disk.
///
/// @return An enum describing the result of running the transaction.
TransactionRunResult run();

Expand Down
33 changes: 24 additions & 9 deletions 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,18 +878,24 @@ Transaction::TransactionRunResult Transaction::Impl::_run(

if (ret == 0) {
// removes any temporarily stored packages from the system
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) {
try {
if (!std::filesystem::remove(file)) {
logger->debug("Temporary file \"{}\" doesn't exist.", file);
// 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) {
try {
if (!std::filesystem::remove(file)) {
logger->debug("Temporary file \"{}\" doesn't exist.", file);
}
} catch (const std::filesystem::filesystem_error & ex) {
logger->debug(
"An error occurred when trying to remove a temporary file \"{}\": {}", file, ex.what());
}
} catch (const std::filesystem::filesystem_error & ex) {
logger->debug("An error occurred when trying to remove a temporary file \"{}\": {}", file, ex.what());
}
temp_files_memory.clear();
}
temp_files_memory.clear();

return TransactionRunResult::SUCCESS;
} else {
Expand Down
Loading