diff --git a/librepomgr/buildactions/buildaction.cpp b/librepomgr/buildactions/buildaction.cpp index 048ec38..1be55d9 100644 --- a/librepomgr/buildactions/buildaction.cpp +++ b/librepomgr/buildactions/buildaction.cpp @@ -478,6 +478,7 @@ void BuildServiceCleanup::run() // get variables from setup auto setupLock = m_setup.lockToRead(); + m_buildActionRetention = m_setup.building.buildActionRetention; m_paccachePath = findExecutable(m_setup.building.paccachePath); const auto packageCachePath = m_setup.building.packageCacheDir; setupLock.unlock(); @@ -506,7 +507,7 @@ void BuildServiceCleanup::run() auto deleted = std::size_t(); constexpr auto stopAt = 150; m_setup.building.forEachBuildAction( - [this, &count, &deleted, twoWeeksAgo = DateTime::gmtNow() - TimeSpan::fromDays(14)]( + [this, &count, &deleted, expirationDate = DateTime::gmtNow() - m_buildActionRetention]( LibPkg::StorageID id, BuildAction &action, ServiceSetup::BuildSetup::VisitorBehavior &visitorBehavior) { if (count <= stopAt) { return true; // abort deletion if under 150 build actions anyways @@ -514,8 +515,9 @@ void BuildServiceCleanup::run() if (m_buildAction->id == id || action.finished.isNull()) { return false; // avoid deleting cleanup action itself as well as any unfinished actions } - if (action.result != BuildActionResult::Success || action.finished > twoWeeksAgo) { - return false; // delete only successful actions that are at least two weeks old + if (action.result != BuildActionResult::Success + || (action.finished > expirationDate && action.type != BuildActionType::BuildServiceCleanup)) { + return false; // delete only successful actions that have expired (unless it is just a cleanup action itself) } visitorBehavior = ServiceSetup::BuildSetup::VisitorBehavior::Delete; ++deleted; diff --git a/librepomgr/buildactions/buildactionprivate.h b/librepomgr/buildactions/buildactionprivate.h index c73b38c..84f4a4b 100644 --- a/librepomgr/buildactions/buildactionprivate.h +++ b/librepomgr/buildactions/buildactionprivate.h @@ -695,6 +695,7 @@ private: std::vector> m_concreteCacheDirs; std::vector>::iterator m_concreteCacheDirsIterator; BuildActionMessages m_messages; + CppUtilities::TimeSpan m_buildActionRetention; bool m_dryCacheCleanup; bool m_dbCleanupConcluded, m_cacheCleanupConcluded; }; diff --git a/librepomgr/helper.h b/librepomgr/helper.h index 31042e0..17eb54d 100644 --- a/librepomgr/helper.h +++ b/librepomgr/helper.h @@ -1,6 +1,8 @@ #ifndef LIBREPOMGR_HELPER_H #define LIBREPOMGR_HELPER_H +#include +#include #include #include #include @@ -63,7 +65,6 @@ inline void convertValue(const std::multimap &multimap template , Traits::IsSpecializationOf> * = nullptr> inline void convertValue(const std::multimap &multimap, const std::string &key, TargetType &result) { - using namespace std; using namespace CppUtilities; using namespace CppUtilities::EscapeCodes; @@ -75,8 +76,7 @@ inline void convertValue(const std::multimap &multimap result = stringToNumber(value); } } catch (const ConversionException &) { - cerr << Phrases::ErrorMessage << "Specified number \"" << value << "\" for key \"" << key << "\" is invalid." << Phrases::End; - return; + std::cerr << Phrases::ErrorMessage << "Specified number \"" << value << "\" for key \"" << key << "\" is invalid." << Phrases::End; } } } @@ -90,16 +90,14 @@ template <> inline void convertValue(const std::multimap inline void convertValue(const std::multimap &multimap, const std::string &key, std::regex &result) { - using namespace std; using namespace CppUtilities::EscapeCodes; if (const char *const value = getLastValue(multimap, key)) { try { result = value; - } catch (const regex_error &e) { - cerr << Phrases::ErrorMessage << "Specified regex \"" << value << "\" for key \"" << key << "\" is invalid: " << Phrases::End; - cerr << e.what() << '\n'; - return; + } catch (const std::regex_error &e) { + std::cerr << Phrases::ErrorMessage << "Specified regex \"" << value << "\" for key \"" << key << "\" is invalid: " << Phrases::End; + std::cerr << e.what() << '\n'; } } } @@ -119,6 +117,20 @@ template <> inline void convertValue(const std::multimap inline void convertValue(const std::multimap &multimap, const std::string &key, CppUtilities::TimeSpan &result) +{ + using namespace CppUtilities::EscapeCodes; + + if (const char *const value = getLastValue(multimap, key)) { + try { + result = CppUtilities::TimeSpan::fromString(value); + } catch (const CppUtilities::ConversionException &e) { + std::cerr << Phrases::ErrorMessage << "Specified duration \"" << value << "\" for key \"" << key << "\" is invalid: " << Phrases::End; + std::cerr << e.what() << '\n'; + } + } +} + template void mergeSecondVectorIntoFirstVector(VectorType &firstVector, VectorType &secondVector) { const auto requiredSize = firstVector.size() + secondVector.size(); diff --git a/librepomgr/serversetup.cpp b/librepomgr/serversetup.cpp index c7a69af..cc65e6e 100644 --- a/librepomgr/serversetup.cpp +++ b/librepomgr/serversetup.cpp @@ -181,6 +181,7 @@ void ServiceSetup::BuildSetup::applyConfig(const std::multimap