This commit is contained in:
Alexander Aleksandrovič Klimov 2026-02-16 09:55:55 +01:00 committed by GitHub
commit 990938c2cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 2 deletions

View file

@ -465,7 +465,7 @@ void ConfigObject::DumpObjects(const String& filename, int attributeTypes)
<< "Dumping program state to file '" << filename << "'";
try {
Utility::Glob(filename + ".tmp.*", &Utility::Remove, GlobFile);
Utility::Glob(filename + ".tmp.*", &Utility::RemoveIfOld, GlobFile);
} catch (const std::exception& ex) {
Log(LogWarning, "ConfigObject") << DiagnosticInformation(ex);
}

View file

@ -723,6 +723,19 @@ void Utility::RemoveDirRecursive(const String& path)
(void)fs::remove_all(fs::path(path.Begin(), path.End()));
}
void Utility::RemoveIfOld(const String& path)
{
namespace fs = boost::filesystem;
fs::path p (path.Begin(), path.End());
boost::system::error_code ec;
auto modTime (fs::last_write_time(p, ec));
if (!ec && modTime < GetTime() - 24 * 60 * 60) {
(void)fs::remove(p);
}
}
/*
* Copies a source file to a target location.
* Caller must ensure that the target's base directory exists and is writable.

View file

@ -120,6 +120,7 @@ public:
static void Remove(const String& path);
static void RemoveDirRecursive(const String& path);
static void RemoveIfOld(const String& path);
static void CopyFile(const String& source, const String& target);
static void RenameFile(const String& source, const String& target);

View file

@ -171,7 +171,7 @@ void IcingaApplication::DumpModifiedAttributes()
String path = Configuration::ModAttrPath;
try {
Utility::Glob(path + ".tmp.*", &Utility::Remove, GlobFile);
Utility::Glob(path + ".tmp.*", &Utility::RemoveIfOld, GlobFile);
} catch (const std::exception& ex) {
Log(LogWarning, "IcingaApplication") << DiagnosticInformation(ex);
}