mirror of https://github.com/Icinga/icinga2.git
Fix return value of Utility::MkDir/MkDirP
None as there are exceptions thrown. fixes #9689
This commit is contained in:
parent
6af771b3bf
commit
7eca257784
|
@ -599,7 +599,7 @@ bool Utility::GlobRecursive(const String& path, const String& pattern, const boo
|
|||
}
|
||||
|
||||
|
||||
bool Utility::MkDir(const String& path, int flags)
|
||||
void Utility::MkDir(const String& path, int flags)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
if (mkdir(path.CStr(), flags) < 0 && errno != EEXIST) {
|
||||
|
@ -610,22 +610,16 @@ bool Utility::MkDir(const String& path, int flags)
|
|||
<< boost::errinfo_api_function("mkdir")
|
||||
<< boost::errinfo_errno(errno));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Utility::MkDirP(const String& path, int flags)
|
||||
void Utility::MkDirP(const String& path, int flags)
|
||||
{
|
||||
size_t pos = 0;
|
||||
|
||||
bool ret = true;
|
||||
|
||||
while (ret && pos != String::NPos) {
|
||||
while (pos != String::NPos) {
|
||||
pos = path.Find("/", pos + 1);
|
||||
ret = MkDir(path.SubStr(0, pos), flags);
|
||||
MkDir(path.SubStr(0, pos), flags);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Utility::RemoveDirRecursive(const String& path)
|
||||
|
|
|
@ -81,8 +81,8 @@ public:
|
|||
|
||||
static bool Glob(const String& pathSpec, const boost::function<void (const String&)>& callback, int type = GlobFile | GlobDirectory);
|
||||
static bool GlobRecursive(const String& path, const String& pattern, const boost::function<void (const String&)>& callback, int type = GlobFile | GlobDirectory);
|
||||
static bool MkDir(const String& path, int flags);
|
||||
static bool MkDirP(const String& path, int flags);
|
||||
static void MkDir(const String& path, int flags);
|
||||
static void MkDirP(const String& path, int flags);
|
||||
static bool SetFileOwnership(const String& file, const String& user, const String& group);
|
||||
|
||||
static void QueueAsyncCallback(const boost::function<void (void)>& callback, SchedulerPolicy policy = DefaultScheduler);
|
||||
|
|
|
@ -72,12 +72,7 @@ int ApiSetupUtility::SetupMasterCertificates(const String& cn)
|
|||
}
|
||||
|
||||
String pki_path = PkiUtility::GetPkiPath();
|
||||
|
||||
if (!Utility::MkDirP(pki_path, 0700)) {
|
||||
Log(LogCritical, "cli")
|
||||
<< "Could not create local pki directory '" << pki_path << "'.";
|
||||
return 1;
|
||||
}
|
||||
Utility::MkDirP(pki_path, 0700);
|
||||
|
||||
String user = ScriptGlobal::Get("RunAsUser");
|
||||
String group = ScriptGlobal::Get("RunAsGroup");
|
||||
|
|
|
@ -309,16 +309,7 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm,
|
|||
/* pki request a signed certificate from the master */
|
||||
|
||||
String pki_path = PkiUtility::GetPkiPath();
|
||||
|
||||
String key = pki_path + "/" + cn + ".key";
|
||||
String cert = pki_path + "/" + cn + ".crt";
|
||||
String ca = pki_path + "/ca.crt";
|
||||
|
||||
if (!Utility::MkDirP(pki_path, 0700)) {
|
||||
Log(LogCritical, "cli")
|
||||
<< "Could not create local pki directory '" << pki_path << "'.";
|
||||
return 1;
|
||||
}
|
||||
Utility::MkDirP(pki_path, 0700);
|
||||
|
||||
String user = ScriptGlobal::Get("RunAsUser");
|
||||
String group = ScriptGlobal::Get("RunAsGroup");
|
||||
|
@ -328,6 +319,10 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm,
|
|||
<< "Cannot set ownership for user '" << user << "' group '" << group << "' on file '" << pki_path << "'. Verify it yourself!";
|
||||
}
|
||||
|
||||
String key = pki_path + "/" + cn + ".key";
|
||||
String cert = pki_path + "/" + cn + ".crt";
|
||||
String ca = pki_path + "/ca.crt";
|
||||
|
||||
if (Utility::PathExists(key))
|
||||
NodeUtility::CreateBackupFile(key, true);
|
||||
if (Utility::PathExists(cert))
|
||||
|
|
|
@ -243,14 +243,7 @@ wizard_master_host:
|
|||
|
||||
/* workaround for fetching the master cert */
|
||||
String pki_path = PkiUtility::GetPkiPath();
|
||||
String node_cert = pki_path + "/" + cn + ".crt";
|
||||
String node_key = pki_path + "/" + cn + ".key";
|
||||
|
||||
if (!Utility::MkDirP(pki_path, 0700)) {
|
||||
Log(LogCritical, "cli")
|
||||
<< "Could not create local pki directory '" << pki_path << "'.";
|
||||
return 1;
|
||||
}
|
||||
Utility::MkDirP(pki_path, 0700);
|
||||
|
||||
String user = ScriptGlobal::Get("RunAsUser");
|
||||
String group = ScriptGlobal::Get("RunAsGroup");
|
||||
|
@ -260,6 +253,9 @@ wizard_master_host:
|
|||
<< "Cannot set ownership for user '" << user << "' group '" << group << "' on file '" << pki_path << "'. Verify it yourself!";
|
||||
}
|
||||
|
||||
String node_cert = pki_path + "/" + cn + ".crt";
|
||||
String node_key = pki_path + "/" + cn + ".key";
|
||||
|
||||
if (Utility::PathExists(node_key))
|
||||
NodeUtility::CreateBackupFile(node_key, true);
|
||||
if (Utility::PathExists(node_cert))
|
||||
|
|
|
@ -53,11 +53,7 @@ int PkiUtility::NewCa(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (!Utility::MkDirP(cadir, 0700)) {
|
||||
Log(LogCritical, "base")
|
||||
<< "Could not create CA directory '" << cadir << "'.";
|
||||
return 1;
|
||||
}
|
||||
Utility::MkDirP(cadir, 0700);
|
||||
|
||||
MakeX509CSR("Icinga CA", cadir + "/ca.key", String(), cadir + "/ca.crt", cadir + "/serial.txt", true);
|
||||
|
||||
|
|
|
@ -137,15 +137,7 @@ void ApiListener::SyncZoneDir(const Zone::Ptr& zone) const
|
|||
Log(LogInformation, "ApiListener")
|
||||
<< "Copying zone configuration files for zone '" << zone->GetName() << "' to '" << oldDir << "'.";
|
||||
|
||||
if (!Utility::MkDir(oldDir, 0700)) {
|
||||
Log(LogCritical, "ApiListener")
|
||||
<< "mkdir() for path '" << oldDir << "' failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
|
||||
|
||||
BOOST_THROW_EXCEPTION(posix_error()
|
||||
<< boost::errinfo_api_function("mkdir")
|
||||
<< boost::errinfo_errno(errno)
|
||||
<< boost::errinfo_file_name(oldDir));
|
||||
}
|
||||
Utility::MkDir(oldDir, 0700);
|
||||
|
||||
Dictionary::Ptr oldConfig = LoadConfigDir(oldDir);
|
||||
|
||||
|
@ -254,15 +246,7 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D
|
|||
|
||||
String oldDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones/" + zone->GetName();
|
||||
|
||||
if (!Utility::MkDir(oldDir, 0700)) {
|
||||
Log(LogCritical, "ApiListener")
|
||||
<< "mkdir() for path '" << oldDir << "' failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
|
||||
|
||||
BOOST_THROW_EXCEPTION(posix_error()
|
||||
<< boost::errinfo_api_function("mkdir")
|
||||
<< boost::errinfo_errno(errno)
|
||||
<< boost::errinfo_file_name(oldDir));
|
||||
}
|
||||
Utility::MkDir(oldDir, 0700);
|
||||
|
||||
Dictionary::Ptr newConfig = kv.second;
|
||||
Dictionary::Ptr oldConfig = LoadConfigDir(oldDir);
|
||||
|
|
Loading…
Reference in New Issue