From a1d4ec6b9257cfaab436d3f277036f69bef8b33b Mon Sep 17 00:00:00 2001 From: ckrause Date: Sun, 15 Dec 2024 14:44:57 +0100 Subject: [PATCH] delete corrupt programs dir in BOINC (#360) --- CHANGELOG.md | 3 +++ src/cmd/boinc.cpp | 16 ++++++++++++++++ src/sys/file.cpp | 13 ++++++++++++- src/sys/file.hpp | 4 +++- src/sys/git.cpp | 5 +++-- src/sys/git.hpp | 3 ++- 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe1246be..6997b609 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,14 @@ To install or update LODA, please follow the [installation instructions](https:/ ## [Unreleased] +## v24.12.15 + ### Enhancements * Improve negativity check in formula generation * Simplify formulas generated from `nrt` operations * Limited support for bit-wise operations in formulas +* Delete corrupt programs directory in BOINC ## v24.12.8 diff --git a/src/cmd/boinc.cpp b/src/cmd/boinc.cpp index ff61fa2f..cbb550ba 100644 --- a/src/cmd/boinc.cpp +++ b/src/cmd/boinc.cpp @@ -123,6 +123,22 @@ void Boinc::run() { checkpoint_key); monitor.writeProgress(); + // check programs dir consistency by updating it + if (Setup::existsProgramsHome()) { + const auto progs_dir = Setup::getProgramsHome(); + FolderLock lock(project_dir); + if (Setup::existsProgramsHome() && // need to check again here + !Git::git(progs_dir, "pull origin main -q --ff-only", false)) { + Log::get().error("Failed to update programs repository", false); + const auto age = getFileAgeInDays(progs_dir); + if (age >= 7) { + Log::get().warn("Deleting corrupt programs directory (age: " + + std::to_string(age) + " days)"); + rmDirRecursive(progs_dir); + } + } + } + // clone programs repository if necessary if (!Setup::existsProgramsHome()) { FolderLock lock(project_dir); diff --git a/src/sys/file.cpp b/src/sys/file.cpp index e3aa2341..ff843633 100644 --- a/src/sys/file.cpp +++ b/src/sys/file.cpp @@ -79,13 +79,24 @@ void ensureDir(const std::string &path) { } } -void execCmd(const std::string &cmd, bool fail_on_error) { +void rmDirRecursive(const std::string &path) { +#ifdef _WIN64 + auto cmd = "rmdir /s /q \"" + path + "\""; +#else + auto cmd = "rm -rf \"" + path + "\""; +#endif + execCmd(cmd); +} + +bool execCmd(const std::string &cmd, bool fail_on_error) { auto exit_code = system(cmd.c_str()); if (exit_code != 0) { Log::get().error("Error executing command (exit code " + std::to_string(exit_code) + "): " + cmd, fail_on_error); + return false; } + return true; } void moveFile(const std::string &from, const std::string &to) { diff --git a/src/sys/file.hpp b/src/sys/file.hpp index bea35d54..99088248 100644 --- a/src/sys/file.hpp +++ b/src/sys/file.hpp @@ -21,9 +21,11 @@ bool isDir(const std::string &path); void ensureDir(const std::string &path); +void rmDirRecursive(const std::string &path); + void moveFile(const std::string &from, const std::string &to); -void execCmd(const std::string &cmd, bool fail_on_error = true); +bool execCmd(const std::string &cmd, bool fail_on_error = true); void makeExecutable(const std::string &path); diff --git a/src/sys/git.cpp b/src/sys/git.cpp index da279250..2079b842 100644 --- a/src/sys/git.cpp +++ b/src/sys/git.cpp @@ -112,7 +112,8 @@ void Git::fixWindowsEnv(std::string project_dir) { } #endif -void Git::git(const std::string &folder, const std::string &args) { +bool Git::git(const std::string &folder, const std::string &args, + bool fail_on_error) { std::string a; if (!folder.empty()) { a = "-C \"" + folder; @@ -130,7 +131,7 @@ void Git::git(const std::string &folder, const std::string &args) { fixWindowsEnv(); } #endif - execCmd("git " + a); + return execCmd("git " + a, fail_on_error); } void Git::clone(const std::string &url, const std::string &folder) { diff --git a/src/sys/git.hpp b/src/sys/git.hpp index 89d42def..91eedbcb 100644 --- a/src/sys/git.hpp +++ b/src/sys/git.hpp @@ -11,7 +11,8 @@ class Git { static void fixWindowsEnv(std::string project_dir = ""); #endif - static void git(const std::string &folder, const std::string &args); + static bool git(const std::string &folder, const std::string &args, + bool fail_on_error = true); static void clone(const std::string &url, const std::string &folder);