diff --git a/lib/base/array.cpp b/lib/base/array.cpp index 9d236954b..d9e8ea06c 100644 --- a/lib/base/array.cpp +++ b/lib/base/array.cpp @@ -108,6 +108,20 @@ size_t Array::GetLength(void) const return m_Data.size(); } +/** + * Checks whether the array contains the specified value. + * + * @param value The value. + * @returns true if the array contains the value, false otherwise. + */ +bool Array::Contains(const String& value) const +{ + ASSERT(!OwnsLock()); + ObjectLock olock(this); + + return (std::find(m_Data.begin(), m_Data.end(), value) != m_Data.end()); +} + /** * Insert the given value at the specified index * diff --git a/lib/base/array.h b/lib/base/array.h index 0e53fbf78..b7e39b0ef 100644 --- a/lib/base/array.h +++ b/lib/base/array.h @@ -50,6 +50,7 @@ public: Iterator End(void); size_t GetLength(void) const; + bool Contains(const String& value) const; void Insert(unsigned int index, const Value& value); void Remove(unsigned int index); diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp index eabce35e3..d60ffaf44 100644 --- a/lib/icinga/checkable.cpp +++ b/lib/icinga/checkable.cpp @@ -94,6 +94,9 @@ void Checkable::AddGroup(const String& name) Array::Ptr groups = GetGroups(); + if (groups && groups->Contains(name)) + return; + if (!groups) groups = make_shared(); diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index ca29c2935..71ab946b8 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -75,6 +75,9 @@ void User::AddGroup(const String& name) Array::Ptr groups = GetGroups(); + if (groups && groups->Contains(name)) + return; + if (!groups) groups = make_shared();