From: Gunnar Beutner Date: Wed, 11 Nov 2015 09:25:18 +0000 (+0100) Subject: Check whether config file exists before trying to create object X-Git-Tag: v2.4.0~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b2364884d87dd59737b36a422e30ff1f11c40b33;p=icinga2 Check whether config file exists before trying to create object fixes #10602 --- diff --git a/lib/remote/configobjectutility.cpp b/lib/remote/configobjectutility.cpp index d6270baad..1747fe71f 100644 --- a/lib/remote/configobjectutility.cpp +++ b/lib/remote/configobjectutility.cpp @@ -111,6 +111,9 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full String path = GetObjectConfigPath(type, fullName); 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); fp << config; fp.close();