]> granicus.if.org Git - icinga2/commitdiff
Check whether config file exists before trying to create object
authorGunnar Beutner <gunnar@beutner.name>
Wed, 11 Nov 2015 09:25:18 +0000 (10:25 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Wed, 11 Nov 2015 09:25:18 +0000 (10:25 +0100)
fixes #10602

lib/remote/configobjectutility.cpp

index d6270baad1d674cbe4827f8259f21fd9f68c91bd..1747fe71f3aec3c13726c6b65e725daaeddcc675 100644 (file)
@@ -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();