From 39213e66a9644d46d2fd9979c75707ff1288d3d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Wed, 18 Sep 2024 13:09:29 +0200 Subject: [PATCH] dnf clean: Do not report an error on a nonexistent cache directory If /var/cache/libdnf5 directory did not exist, "dnf clean all" reported and error: Cannot iterate the cache directory: "/var/cache/libdnf5" This patch optimizes this case to no operation. If there is no cache, there is nothing to remove. If the iterator fails for a different reason, the message is ammended with an operating system error message, explaining the cause. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2313032 --- dnf5/commands/clean/clean.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dnf5/commands/clean/clean.cpp b/dnf5/commands/clean/clean.cpp index deaa76206..4e74286c5 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(