From c6ca49eeac4daa1b33f1aebf0503a1945f0a1a1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= Date: Wed, 13 Dec 2023 15:29:16 +0100 Subject: [PATCH] Unify system::State::save() exceptions to `FileSystemError` The same exception can come from `utils::fs::File`. --- libdnf5/system/state.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libdnf5/system/state.cpp b/libdnf5/system/state.cpp index e31301429..6d1426d78 100644 --- a/libdnf5/system/state.cpp +++ b/libdnf5/system/state.cpp @@ -21,6 +21,7 @@ along with libdnf. If not, see . #include "utils/string.hpp" +#include "libdnf5/common/exception.hpp" #include "libdnf5/utils/bgettext/bgettext-mark-domain.h" #include "libdnf5/utils/fs/file.hpp" #include "libdnf5/utils/fs/temp.hpp" @@ -501,7 +502,11 @@ static std::string toml_format(const toml::value & value) { void State::save() { - std::filesystem::create_directories(path); + std::error_code ec; + std::filesystem::create_directories(path, ec); + if (ec) { + throw FileSystemError(errno, path, M_("{}"), ec.message()); + } utils::fs::File(get_package_state_path(), "w").write(toml_format(make_top_value("packages", package_states))); utils::fs::File(get_nevra_state_path(), "w").write(toml_format(make_top_value("nevras", nevra_states)));