Replace existing mkdir() calls with Utility::MkDir()

refs #6328
This commit is contained in:
Michael Friedrich 2014-06-13 09:23:05 +02:00
parent 1eb77b0cd7
commit dea57e9dcf
1 changed files with 15 additions and 11 deletions

View File

@ -110,11 +110,11 @@ void ApiListener::SyncZoneDir(const Zone::Ptr& zone) const
String newDir = Application::GetZonesDir() + "/" + zone->GetName(); String newDir = Application::GetZonesDir() + "/" + zone->GetName();
String oldDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones/" + zone->GetName(); String oldDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones/" + zone->GetName();
#ifndef _WIN32 if (!Utility::MkDir(oldDir, 0700)) {
if (mkdir(oldDir.CStr(), 0700) < 0 && errno != EEXIST) { std::ostringstream msgbuf;
#else /*_ WIN32 */ msgbuf << "mkdir() for path '" << oldDir << "'failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
if (mkdir(oldDir.CStr()) < 0 && errno != EEXIST) { Log(LogCritical, "ApiListener", msgbuf.str());
#endif /* _WIN32 */
BOOST_THROW_EXCEPTION(posix_error() BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("mkdir") << boost::errinfo_api_function("mkdir")
<< boost::errinfo_errno(errno) << boost::errinfo_errno(errno)
@ -133,7 +133,11 @@ void ApiListener::SyncZoneDirs(void) const
if (!IsConfigMaster(zone)) if (!IsConfigMaster(zone))
continue; continue;
SyncZoneDir(zone); try {
SyncZoneDir(zone);
} catch (std::exception&) {
continue;
}
} }
} }
@ -213,11 +217,11 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin& origin, const Dictio
String oldDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones/" + zone->GetName(); String oldDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones/" + zone->GetName();
#ifndef _WIN32 if (!Utility::MkDir(oldDir, 0700)) {
if (mkdir(oldDir.CStr(), 0700) < 0 && errno != EEXIST) { std::ostringstream msgbuf;
#else /*_ WIN32 */ msgbuf << "mkdir() for path '" << oldDir << "'failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
if (mkdir(oldDir.CStr()) < 0 && errno != EEXIST) { Log(LogCritical, "ApiListener", msgbuf.str());
#endif /* _WIN32 */
BOOST_THROW_EXCEPTION(posix_error() BOOST_THROW_EXCEPTION(posix_error()
<< boost::errinfo_api_function("mkdir") << boost::errinfo_api_function("mkdir")
<< boost::errinfo_errno(errno) << boost::errinfo_errno(errno)