diff --git a/dnf5/commands/clean/clean.cpp b/dnf5/commands/clean/clean.cpp
index deaa762063..b4ac4bbd62 100644
--- a/dnf5/commands/clean/clean.cpp
+++ b/dnf5/commands/clean/clean.cpp
@@ -22,10 +22,12 @@ along with libdnf. If not, see .
#include "dnf5/shared_options.hpp"
+#include
#include
#include
#include
#include
+#include
#include
#include
@@ -168,7 +170,14 @@ void CleanCommand::run() {
}
if (ec) {
- throw std::runtime_error(fmt::format("Cannot iterate the cache directory: \"{}\"", cachedir.string()));
+ if (ec.value() == ENOENT) {
+ std::cout << libdnf5::utils::sformat(
+ _("Cache directory \"{}\" does not exist. Nothing to clean."), cachedir.string())
+ << std::endl;
+ return;
+ }
+ throw std::runtime_error(libdnf5::utils::sformat(
+ _("Cannot iterate cache directory \"{}\": {}"), cachedir.string(), ec.message()));
}
std::cout << fmt::format(