check error when creating directory
Change-Id: Iccff91eea9c3a5ab7b84a24688d80d3ea6fdec5e
diff --git a/tools/dhtnet_crtmgr/dhtnet_crtmgr.cpp b/tools/dhtnet_crtmgr/dhtnet_crtmgr.cpp
index 3d3d94a..814dbe2 100644
--- a/tools/dhtnet_crtmgr/dhtnet_crtmgr.cpp
+++ b/tools/dhtnet_crtmgr/dhtnet_crtmgr.cpp
@@ -43,8 +43,12 @@
dht::crypto::Identity generateIdentity(const std::filesystem::path& path_id, const std::string& name, const dht::crypto::Identity& ca)
{
auto identity = dht::crypto::generateIdentity(name, ca);
- if (!std::filesystem::exists(path_id))
- std::filesystem::create_directories(path_id);
+ std::error_code ec;
+ std::filesystem::create_directories(path_id, ec);
+ if (ec) {
+ fmt::print(stderr, "Error: failed to create directory {}\n", path_id.string());
+ return {};
+ }
dht::crypto::saveIdentity(identity, path_id / name);
return identity;
}