diff --git a/lib/remote/apilistener-configsync.cpp b/lib/remote/apilistener-configsync.cpp index 627141166..a12db0bca 100644 --- a/lib/remote/apilistener-configsync.cpp +++ b/lib/remote/apilistener-configsync.cpp @@ -332,17 +332,7 @@ void ApiListener::UpdateConfigObject(const ConfigObject::Ptr& object, const Mess params->Set("zone", zoneName); if (object->GetPackage() == "_api") { - String file; - - try { - file = ConfigObjectUtility::GetObjectConfigPath(object->GetReflectionType(), object->GetName()); - } catch (const std::exception& ex) { - Log(LogNotice, "ApiListener") - << "Cannot sync object '" << object->GetName() << "': " << ex.what(); - return; - } - - std::ifstream fp(file.CStr(), std::ifstream::binary); + std::ifstream fp(ConfigObjectUtility::GetExistingObjectConfigPath(object).CStr(), std::ifstream::binary); if (!fp) return; diff --git a/lib/remote/configobjectutility.cpp b/lib/remote/configobjectutility.cpp index b4fa9ac5c..db30f283a 100644 --- a/lib/remote/configobjectutility.cpp +++ b/lib/remote/configobjectutility.cpp @@ -29,7 +29,7 @@ String ConfigObjectUtility::GetConfigDir() return prefix + activeStage; } -String ConfigObjectUtility::GetObjectConfigPath(const Type::Ptr& type, const String& fullName) +String ConfigObjectUtility::ComputeNewObjectConfigPath(const Type::Ptr& type, const String& fullName) { String typeDir = type->GetPluralName(); boost::algorithm::to_lower(typeDir); @@ -51,8 +51,10 @@ String ConfigObjectUtility::GetObjectConfigPath(const Type::Ptr& type, const Str * be able to schedule a downtime or add an acknowledgement, which is not feasible) and the impact of not syncing * these objects through the whole cluster is limited. For other object types, we currently prefer to fail the * creation early so that configuration inconsistencies throughout the cluster are avoided. + * + * TODO: Remove this in v2.16 and truncate all. */ - if ((type->GetName() != "Comment" && type->GetName() != "Downtime") || Utility::PathExists(longPath)) { + if (type->GetName() != "Comment" && type->GetName() != "Downtime") { return longPath; } @@ -60,6 +62,11 @@ String ConfigObjectUtility::GetObjectConfigPath(const Type::Ptr& type, const Str return prefix + Utility::TruncateUsingHash<80+3+40>(escapedName) + ".conf"; } +String ConfigObjectUtility::GetExistingObjectConfigPath(const ConfigObject::Ptr& object) +{ + return object->GetDebugInfo().Path; +} + void ConfigObjectUtility::RepairPackage(const String& package) { /* Try to fix the active stage, whenever we find a directory in there. @@ -185,7 +192,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full String path; try { - path = GetObjectConfigPath(type, fullName); + path = ComputeNewObjectConfigPath(type, fullName); } catch (const std::exception& ex) { errors->Add("Config package broken: " + DiagnosticInformation(ex, false)); return false; @@ -346,17 +353,10 @@ bool ConfigObjectUtility::DeleteObjectHelper(const ConfigObject::Ptr& object, bo return false; } - String path; - - try { - path = GetObjectConfigPath(object->GetReflectionType(), name); - } catch (const std::exception& ex) { - errors->Add("Config package broken: " + DiagnosticInformation(ex, false)); - return false; + if (object->GetPackage() == "_api") { + Utility::Remove(GetExistingObjectConfigPath(object)); } - Utility::Remove(path); - Log(LogInformation, "ConfigObjectUtility") << "Deleted object '" << name << "' of type '" << type->GetName() << "'."; diff --git a/lib/remote/configobjectutility.hpp b/lib/remote/configobjectutility.hpp index f383a211b..5a113c82e 100644 --- a/lib/remote/configobjectutility.hpp +++ b/lib/remote/configobjectutility.hpp @@ -22,7 +22,8 @@ class ConfigObjectUtility public: static String GetConfigDir(); - static String GetObjectConfigPath(const Type::Ptr& type, const String& fullName); + static String ComputeNewObjectConfigPath(const Type::Ptr& type, const String& fullName); + static String GetExistingObjectConfigPath(const ConfigObject::Ptr& object); static void RepairPackage(const String& package); static void CreateStorage();