| 33 | } |
| 34 | |
| 35 | String ConfigObjectUtility::ComputeNewObjectConfigPath(const Type::Ptr& type, const String& fullName) |
| 36 | { |
| 37 | String typeDir = type->GetPluralName(); |
| 38 | boost::algorithm::to_lower(typeDir); |
| 39 | |
| 40 | /* This may throw an exception the caller above must handle. */ |
| 41 | String prefix = GetConfigDir() + "/conf.d/" + type->GetPluralName().ToLower() + "/"; |
| 42 | |
| 43 | String escapedName = EscapeName(fullName); |
| 44 | |
| 45 | String longPath = prefix + escapedName + ".conf"; |
| 46 | |
| 47 | /* |
| 48 | * The long path may cause trouble due to exceeding the allowed filename length of the filesystem. Therefore, the |
| 49 | * preferred solution would be to use the truncated and hashed version as returned at the end of this function. |
| 50 | * However, for compatibility reasons, we have to keep the old long version in some cases. Notably, this could lead |
| 51 | * to the creation of objects that can't be synced to child nodes if they are running an older version. Thus, for |
| 52 | * now, the fix is only enabled for comments and downtimes, as these are the object types for which the issue is |
| 53 | * most likely triggered but can't be worked around easily (you'd have to rename the host and/or service in order to |
| 54 | * be able to schedule a downtime or add an acknowledgement, which is not feasible) and the impact of not syncing |
| 55 | * these objects through the whole cluster is limited. For other object types, we currently prefer to fail the |
| 56 | * creation early so that configuration inconsistencies throughout the cluster are avoided. |
| 57 | * |
| 58 | * TODO: Remove this in v2.16 and truncate all. |
| 59 | */ |
| 60 | if (type->GetName() != "Comment" && type->GetName() != "Downtime") { |
| 61 | return longPath; |
| 62 | } |
| 63 | |
| 64 | /* Maximum length 80 bytes object name + 3 bytes "..." + 40 bytes SHA1 (hex-encoded) */ |
| 65 | return prefix + Utility::TruncateUsingHash<80+3+40>(escapedName) + ".conf"; |
| 66 | } |
| 67 | |
| 68 | String ConfigObjectUtility::GetExistingObjectConfigPath(const ConfigObject::Ptr& object) |
| 69 | { |
nothing calls this directly
no test coverage detected