Skip to content

Commit

Permalink
transaction: Remove cached packages only on keepcache
Browse files Browse the repository at this point in the history
In order to have a easier workflow for making package caching exceptions for some commands and also to match the `keepcache` behavior with the original dnf in this matter, the cached files are now removed only when `keepcache` option is turned off at the moment.
  • Loading branch information
jan-kolarik committed Sep 15, 2023
1 parent 88d747e commit c0bdd92
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions libdnf5/base/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,18 +869,21 @@ 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);
if (!config.get_keepcache_option().get_value()) {
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

0 comments on commit c0bdd92

Please sign in to comment.