From c0bdd926c70194d96dd240d2ae5518ad710bedc5 Mon Sep 17 00:00:00 2001 From: Jan Kolarik Date: Fri, 15 Sep 2023 09:08:55 +0000 Subject: [PATCH] transaction: Remove cached packages only on keepcache 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. --- libdnf5/base/transaction.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/libdnf5/base/transaction.cpp b/libdnf5/base/transaction.cpp index 67285c543..9424cab03 100644 --- a/libdnf5/base/transaction.cpp +++ b/libdnf5/base/transaction.cpp @@ -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 {