mirror of https://github.com/Icinga/icinga2.git
Cli: 'repository host remove' cleans service directory, add pending changes helper
refs #7249 fixes #7460
This commit is contained in:
parent
dfd7741a1d
commit
7e73533ad4
|
@ -203,6 +203,14 @@ bool RepositoryUtility::ClearChangeLog(void)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RepositoryUtility::ChangeLogHasPendingChanges(void)
|
||||||
|
{
|
||||||
|
Array::Ptr changelog = make_shared<Array>();
|
||||||
|
GetChangeLog(boost::bind(RepositoryUtility::CollectChange, _1, boost::ref(changelog)));
|
||||||
|
|
||||||
|
return changelog->GetLength() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* commit changelog */
|
/* commit changelog */
|
||||||
bool RepositoryUtility::CommitChangeLog(void)
|
bool RepositoryUtility::CommitChangeLog(void)
|
||||||
{
|
{
|
||||||
|
@ -264,8 +272,28 @@ bool RepositoryUtility::AddObjectInternal(const String& name, const String& type
|
||||||
bool RepositoryUtility::RemoveObjectInternal(const String& name, const String& type, const Dictionary::Ptr& attrs)
|
bool RepositoryUtility::RemoveObjectInternal(const String& name, const String& type, const Dictionary::Ptr& attrs)
|
||||||
{
|
{
|
||||||
String path = GetRepositoryObjectConfigPath(type, attrs) + "/" + name + ".conf";
|
String path = GetRepositoryObjectConfigPath(type, attrs) + "/" + name + ".conf";
|
||||||
|
bool success = RemoveObjectFileInternal(path);
|
||||||
|
|
||||||
return RemoveObjectFileInternal(path);
|
/* special treatment for hosts -> remove the services too */
|
||||||
|
if (type == "Host") {
|
||||||
|
path = GetRepositoryObjectConfigPath(type, attrs) + "/" + name;
|
||||||
|
|
||||||
|
std::vector<String> files;
|
||||||
|
Utility::GlobRecursive(path, "*.conf",
|
||||||
|
boost::bind(&RepositoryUtility::CollectObjects, _1, boost::ref(files)), GlobFile);
|
||||||
|
|
||||||
|
BOOST_FOREACH(const String& file, files) {
|
||||||
|
RemoveObjectFileInternal(file);
|
||||||
|
}
|
||||||
|
#ifndef _WIN32
|
||||||
|
rmdir(path.CStr());
|
||||||
|
#else
|
||||||
|
_rmdir(path.CStr());
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RepositoryUtility::RemoveObjectFileInternal(const String& path)
|
bool RepositoryUtility::RemoveObjectFileInternal(const String& path)
|
||||||
|
@ -276,7 +304,7 @@ bool RepositoryUtility::RemoveObjectFileInternal(const String& path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlink(path.CStr()) < 0) {
|
if (unlink(path.CStr()) < 0) {
|
||||||
Log(LogCritical, "cli", "Cannot remove file '" + path +
|
Log(LogCritical, "cli", "Cannot remove path '" + path +
|
||||||
"'. Failed with error code " + Convert::ToString(errno) + ", \"" + Utility::FormatErrorNumber(errno) + "\".");
|
"'. Failed with error code " + Convert::ToString(errno) + ", \"" + Utility::FormatErrorNumber(errno) + "\".");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ public:
|
||||||
|
|
||||||
static bool CommitChangeLog(void);
|
static bool CommitChangeLog(void);
|
||||||
static bool ClearChangeLog(void);
|
static bool ClearChangeLog(void);
|
||||||
|
static bool ChangeLogHasPendingChanges(void);
|
||||||
|
|
||||||
static std::vector<String> GetObjects(void);
|
static std::vector<String> GetObjects(void);
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue