Skip to content

Commit

Permalink
delete corrupt programs dir in BOINC (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckrause authored Dec 15, 2024
1 parent dcfd39c commit a1d4ec6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions src/cmd/boinc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion src/sys/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/sys/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions src/sys/git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/sys/git.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit a1d4ec6

Please sign in to comment.