Fix persistent data directory creation
The commit c282e8b6c7f7f4e4ec94e4d1f1a380803e13da08 [1] causes an error
like
```
Oct 23 16:46:25 p10bmc bmcwebd[8985]: [CRITICAL persistent_data.hpp:220] Can't create persistent folders Invalid argument
```
It is because the given persistent data filename does not contain the
directory name.
Tested:
- Update subscription data like
```
curl -k -X PATCH https://${bmc}/redfish/v1/EventService/Subscriptions/${SUBID} \
-H "Content-Type: application/json" \
-d '{"VerifyCertificate": false}'
```
- And check the above error.
- Restart bmcweb and check whether it is stored
[1] https://gerrit.openbmc.org/c/openbmc/bmcweb/+/75314
Change-Id: I0aa4768bbdb195b5247fd30c5078ada60187a4b3
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/include/persistent_data.hpp b/include/persistent_data.hpp
index 625503a..ef2adf3 100644
--- a/include/persistent_data.hpp
+++ b/include/persistent_data.hpp
@@ -212,13 +212,16 @@
{
std::filesystem::path path(filename);
path = path.parent_path();
- std::error_code ecDir;
- std::filesystem::create_directories(path, ecDir);
- if (ecDir)
+ if (!path.empty())
{
- BMCWEB_LOG_CRITICAL("Can't create persistent folders {}",
- ecDir.message());
- return;
+ std::error_code ecDir;
+ std::filesystem::create_directories(path, ecDir);
+ if (ecDir)
+ {
+ BMCWEB_LOG_CRITICAL("Can't create persistent folders {}",
+ ecDir.message());
+ return;
+ }
}
boost::beast::file_posix persistentFile;
boost::system::error_code ec;