From 18c2dae9418e0a418de064f065984d032a72a3d5 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 11 Jan 2021 18:58:22 +0100 Subject: [PATCH] Clean up temp files refs #5124 --- lib/base/configobject.cpp | 6 ++++++ lib/icinga/icingaapplication.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/lib/base/configobject.cpp b/lib/base/configobject.cpp index 8d3e07656..c25fb078c 100644 --- a/lib/base/configobject.cpp +++ b/lib/base/configobject.cpp @@ -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); diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index 074c26dbc..27a64a1e1 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -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);