Cli: Don't allow to override existing repository objects

refs #7255
This commit is contained in:
Michael Friedrich 2014-10-28 19:55:46 +01:00
parent 64298c35ef
commit 2e6a604706
1 changed files with 16 additions and 0 deletions

View File

@ -192,6 +192,22 @@ public:
/* modify objects and write changelog */
bool RepositoryUtility::AddObject(const String& name, const String& type, const Dictionary::Ptr& attrs)
{
std::vector<String> object_paths = GetObjects();
String pattern;
if (type == "Service")
pattern = attrs->Get("host_name") + "/" + name + ".conf";
else
pattern = name + ".conf";
BOOST_FOREACH(const String& object_path, object_paths) {
if (object_path.Contains(pattern)) {
Log(LogWarning, "cli")
<< type << " '" << name << "' already exists. Skipping creation.";
return false;
}
}
/* add a new changelog entry by timestamp */
String path = GetRepositoryChangeLogPath() + "/" + Convert::ToString(Utility::GetTime()) + "-" + type + "-" + SHA256(name) + ".change";