}
}
+void Utility::Remove(const String& path)
+{
+ namespace fs = boost::filesystem;
+
+ (void)fs::remove(fs::path(path.Begin(), path.End()));
+}
+
void Utility::RemoveDirRecursive(const String& path)
{
namespace fs = boost::filesystem;
static bool PathExists(const String& path);
+ static void Remove(const String& path);
static void RemoveDirRecursive(const String& path);
static void CopyFile(const String& source, const String& target);
static void RenameFile(const String& source, const String& target);
}
/* Remove the checkresult files. */
- if (unlink(path.CStr()) < 0)
- BOOST_THROW_EXCEPTION(posix_error()
- << boost::errinfo_api_function("unlink")
- << boost::errinfo_errno(errno)
- << boost::errinfo_file_name(path));
-
- if (unlink(crfile.CStr()) < 0)
- BOOST_THROW_EXCEPTION(posix_error()
- << boost::errinfo_api_function("unlink")
- << boost::errinfo_errno(errno)
- << boost::errinfo_file_name(crfile));
+ Utility::Remove(path);
+
+ Utility::Remove(crfile);
Checkable::Ptr checkable;
if (S_ISFIFO(statbuf.st_mode) && access(commandPath.CStr(), R_OK) >= 0) {
fifo_ok = true;
} else {
- if (unlink(commandPath.CStr()) < 0) {
- BOOST_THROW_EXCEPTION(posix_error()
- << boost::errinfo_api_function("unlink")
- << boost::errinfo_errno(errno)
- << boost::errinfo_file_name(commandPath));
- }
+ Utility::Remove(commandPath);
}
}
{
String path = Configuration::CacheDir + "/api-state.json";
- if (Utility::PathExists(path)) {
- if (unlink(path.CStr()) < 0 && errno != ENOENT) {
- BOOST_THROW_EXCEPTION(posix_error()
- << boost::errinfo_api_function("unlink")
- << boost::errinfo_errno(errno)
- << boost::errinfo_file_name(path));
- }
- }
+ Utility::Remove(path);
}
/* Disable logging for object creation, but do so ourselves later on. */
if (!ConfigItem::CommitItems(ascope.GetContext(), upq, newItems, true) || !ConfigItem::ActivateItems(upq, newItems, true, true)) {
if (errors) {
- if (unlink(path.CStr()) < 0 && errno != ENOENT) {
- BOOST_THROW_EXCEPTION(posix_error()
- << boost::errinfo_api_function("unlink")
- << boost::errinfo_errno(errno)
- << boost::errinfo_file_name(path));
- }
+ Utility::Remove(path);
for (const boost::exception_ptr& ex : upq.GetExceptions()) {
errors->Add(DiagnosticInformation(ex, false));
<< "Created and activated object '" << fullName << "' of type '" << type->GetName() << "'.";
} catch (const std::exception& ex) {
- if (unlink(path.CStr()) < 0 && errno != ENOENT) {
- BOOST_THROW_EXCEPTION(posix_error()
- << boost::errinfo_api_function("unlink")
- << boost::errinfo_errno(errno)
- << boost::errinfo_file_name(path));
- }
+ Utility::Remove(path);
if (errors)
errors->Add(DiagnosticInformation(ex, false));
String path = GetObjectConfigPath(object->GetReflectionType(), name);
- if (Utility::PathExists(path)) {
- if (unlink(path.CStr()) < 0 && errno != ENOENT) {
- BOOST_THROW_EXCEPTION(posix_error()
- << boost::errinfo_api_function("unlink")
- << boost::errinfo_errno(errno)
- << boost::errinfo_file_name(path));
- }
- }
+ Utility::Remove(path);
return true;
}
/* Remove ticket for successful signing request. */
String ticketPath = ApiListener::GetCertsDir() + "/ticket";
- if (unlink(ticketPath.CStr()) < 0 && errno != ENOENT) {
- BOOST_THROW_EXCEPTION(posix_error()
- << boost::errinfo_api_function("unlink")
- << boost::errinfo_errno(errno)
- << boost::errinfo_file_name(ticketPath));
- }
+ Utility::Remove(ticketPath);
/* Update the certificates at runtime and reconnect all endpoints. */
Log(LogInformation, "JsonRpcConnection")