Clean up temp files

refs #5124
This commit is contained in:
Alexander A. Klimov 2021-01-11 18:58:22 +01:00
parent 5f548c8f89
commit 18c2dae941
2 changed files with 13 additions and 0 deletions

View File

@ -468,6 +468,12 @@ void ConfigObject::DumpObjects(const String& filename, int attributeTypes)
Log(LogInformation, "ConfigObject")
<< "Dumping program state to file '" << filename << "'";
try {
Utility::Glob(filename + ".*", &Utility::Remove, GlobFile);
} catch (const std::exception& ex) {
Log(LogWarning, "ConfigObject") << DiagnosticInformation(ex);
}
std::fstream fp;
String tempFilename = Utility::CreateTempFile(filename + ".XXXXXX", 0600, fp);
fp.exceptions(std::ofstream::failbit | std::ofstream::badbit);

View File

@ -7,6 +7,7 @@
#include "config/configcompiler.hpp"
#include "base/configwriter.hpp"
#include "base/configtype.hpp"
#include "base/exception.hpp"
#include "base/logger.hpp"
#include "base/objectlock.hpp"
#include "base/convert.hpp"
@ -163,6 +164,12 @@ void IcingaApplication::DumpModifiedAttributes()
{
String path = Configuration::ModAttrPath;
try {
Utility::Glob(path + ".*", &Utility::Remove, GlobFile);
} catch (const std::exception& ex) {
Log(LogWarning, "IcingaApplication") << DiagnosticInformation(ex);
}
std::fstream fp;
String tempFilename = Utility::CreateTempFile(path + ".XXXXXX", 0644, fp);
fp.exceptions(std::ofstream::failbit | std::ofstream::badbit);