Merge pull request #8025 from Icinga/bugfix/downtime-for-host-service-with-long-name-8022

ConfigObjectUtility::GetObjectConfigPath(): hash names of not already existing objects
This commit is contained in:
Alexander Aleksandrovič Klimov 2021-01-14 10:42:04 +01:00 committed by GitHub
commit 5efe3e662c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -8,11 +8,13 @@
#include "base/configwriter.hpp"
#include "base/exception.hpp"
#include "base/dependencygraph.hpp"
#include "base/tlsutility.hpp"
#include "base/utility.hpp"
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/filesystem.hpp>
#include <boost/system/error_code.hpp>
#include <fstream>
#include <utility>
using namespace icinga;
@ -35,8 +37,13 @@ String ConfigObjectUtility::GetObjectConfigPath(const Type::Ptr& type, const Str
/* This may throw an exception the caller above must handle. */
String prefix = GetConfigDir();
return prefix + "/conf.d/" + typeDir +
"/" + EscapeName(fullName) + ".conf";
auto old (prefix + "/conf.d/" + typeDir + "/" + EscapeName(fullName) + ".conf");
if (fullName.GetLength() <= 80u + 3u /* "..." */ + 40u /* hex SHA1 */ || Utility::PathExists(old)) {
return std::move(old);
}
return prefix + "/conf.d/" + typeDir + "/" + fullName.SubStr(0, 80) + "..." + SHA1(fullName) + ".conf";
}
void ConfigObjectUtility::RepairPackage(const String& package)