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

dnf clean: Do not report an error on a nonexistent cache directory #1707

Merged
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
11 changes: 10 additions & 1 deletion dnf5/commands/clean/clean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "dnf5/shared_options.hpp"

#include <errno.h>
#include <libdnf5-cli/argument_parser.hpp>
#include <libdnf5/repo/repo_cache.hpp>
#include <libdnf5/utils/bgettext/bgettext-lib.h>
#include <libdnf5/utils/bgettext/bgettext-mark-domain.h>
#include <libdnf5/utils/format.hpp>

#include <filesystem>
#include <iostream>
Expand Down Expand Up @@ -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(
Expand Down
Loading