mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 22:54:57 +02:00
Check whether config file exists before trying to create object
fixes #10602
This commit is contained in:
parent
e3c75faabc
commit
b2364884d8
@ -111,6 +111,9 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
|
|||||||
String path = GetObjectConfigPath(type, fullName);
|
String path = GetObjectConfigPath(type, fullName);
|
||||||
Utility::MkDirP(Utility::DirName(path), 0700);
|
Utility::MkDirP(Utility::DirName(path), 0700);
|
||||||
|
|
||||||
|
if (Utility::PathExists(path))
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Configuration file '" + path + "' already exists."));
|
||||||
|
|
||||||
std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::trunc);
|
std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::trunc);
|
||||||
fp << config;
|
fp << config;
|
||||||
fp.close();
|
fp.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user