From 4c521c3c34162b6a5930ac1d78da3456f9b69283 Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Sun, 7 Apr 2024 13:47:06 -0700 Subject: Fix file removal This code used std::remove, which is a mechanism for removing characters from strings. Clearly it meant std::filesystem::remove(), which removes files from the filesystem. Correct it. Change-Id: I030966203c1682a11c723c596accdf34637dd1ba Signed-off-by: Ed Tanous --- include/hostname_monitor.hpp | 7 ++++++- include/nbd_proxy.hpp | 9 +++++++-- redfish-core/include/event_service_manager.hpp | 13 +++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/hostname_monitor.hpp b/include/hostname_monitor.hpp index 6339a6b414..188deff564 100644 --- a/include/hostname_monitor.hpp +++ b/include/hostname_monitor.hpp @@ -28,7 +28,12 @@ inline void installCertificate(const std::filesystem::path& certPath) BMCWEB_LOG_INFO("Replace HTTPs Certificate Success, " "remove temporary certificate file.."); - remove(certPath.c_str()); + std::error_code ec2; + std::filesystem::remove(certPath.c_str(), ec2); + if (ec2) + { + BMCWEB_LOG_ERROR("Failed to remove certificate"); + } }, "xyz.openbmc_project.Certs.Manager.Server.Https", "/xyz/openbmc_project/certs/server/https/1", diff --git a/include/nbd_proxy.hpp b/include/nbd_proxy.hpp index 838e7a1d2c..9607ddfb10 100644 --- a/include/nbd_proxy.hpp +++ b/include/nbd_proxy.hpp @@ -63,8 +63,13 @@ struct NbdProxyServer : std::enable_shared_from_this boost::system::error_code ec; peerSocket.close(ec); - BMCWEB_LOG_DEBUG("std::remove({})", socketId); - std::remove(socketId.c_str()); + BMCWEB_LOG_DEBUG("std::filesystem::remove({})", socketId); + std::error_code ec2; + std::filesystem::remove(socketId.c_str(), ec2); + if (ec2) + { + BMCWEB_LOG_DEBUG("Failed to remove file, ignoring"); + } crow::connections::systemBus->async_method_call( dbus::utility::logError, "xyz.openbmc_project.VirtualMedia", path, diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp index 9872bf8410..0c12cd31ea 100644 --- a/redfish-core/include/event_service_manager.hpp +++ b/redfish-core/include/event_service_manager.hpp @@ -766,8 +766,17 @@ class EventServiceManager } persistent_data::getConfig().writeData(); - std::remove(eventServiceFile); - BMCWEB_LOG_DEBUG("Remove old eventservice config"); + std::error_code ec; + std::filesystem::remove(eventServiceFile, ec); + if (ec) + { + BMCWEB_LOG_DEBUG( + "Failed to remove old event service file. Ignoring"); + } + else + { + BMCWEB_LOG_DEBUG("Remove old eventservice config"); + } } } -- cgit v1.2.3