Skip to content

Commit a1d4ec6

Browse files
authored
delete corrupt programs dir in BOINC (#360)
1 parent dcfd39c commit a1d4ec6

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ To install or update LODA, please follow the [installation instructions](https:/
22

33
## [Unreleased]
44

5+
## v24.12.15
6+
57
### Enhancements
68

79
* Improve negativity check in formula generation
810
* Simplify formulas generated from `nrt` operations
911
* Limited support for bit-wise operations in formulas
12+
* Delete corrupt programs directory in BOINC
1013

1114
## v24.12.8
1215

src/cmd/boinc.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ void Boinc::run() {
123123
checkpoint_key);
124124
monitor.writeProgress();
125125

126+
// check programs dir consistency by updating it
127+
if (Setup::existsProgramsHome()) {
128+
const auto progs_dir = Setup::getProgramsHome();
129+
FolderLock lock(project_dir);
130+
if (Setup::existsProgramsHome() && // need to check again here
131+
!Git::git(progs_dir, "pull origin main -q --ff-only", false)) {
132+
Log::get().error("Failed to update programs repository", false);
133+
const auto age = getFileAgeInDays(progs_dir);
134+
if (age >= 7) {
135+
Log::get().warn("Deleting corrupt programs directory (age: " +
136+
std::to_string(age) + " days)");
137+
rmDirRecursive(progs_dir);
138+
}
139+
}
140+
}
141+
126142
// clone programs repository if necessary
127143
if (!Setup::existsProgramsHome()) {
128144
FolderLock lock(project_dir);

src/sys/file.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,24 @@ void ensureDir(const std::string &path) {
7979
}
8080
}
8181

82-
void execCmd(const std::string &cmd, bool fail_on_error) {
82+
void rmDirRecursive(const std::string &path) {
83+
#ifdef _WIN64
84+
auto cmd = "rmdir /s /q \"" + path + "\"";
85+
#else
86+
auto cmd = "rm -rf \"" + path + "\"";
87+
#endif
88+
execCmd(cmd);
89+
}
90+
91+
bool execCmd(const std::string &cmd, bool fail_on_error) {
8392
auto exit_code = system(cmd.c_str());
8493
if (exit_code != 0) {
8594
Log::get().error("Error executing command (exit code " +
8695
std::to_string(exit_code) + "): " + cmd,
8796
fail_on_error);
97+
return false;
8898
}
99+
return true;
89100
}
90101

91102
void moveFile(const std::string &from, const std::string &to) {

src/sys/file.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ bool isDir(const std::string &path);
2121

2222
void ensureDir(const std::string &path);
2323

24+
void rmDirRecursive(const std::string &path);
25+
2426
void moveFile(const std::string &from, const std::string &to);
2527

26-
void execCmd(const std::string &cmd, bool fail_on_error = true);
28+
bool execCmd(const std::string &cmd, bool fail_on_error = true);
2729

2830
void makeExecutable(const std::string &path);
2931

src/sys/git.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ void Git::fixWindowsEnv(std::string project_dir) {
112112
}
113113
#endif
114114

115-
void Git::git(const std::string &folder, const std::string &args) {
115+
bool Git::git(const std::string &folder, const std::string &args,
116+
bool fail_on_error) {
116117
std::string a;
117118
if (!folder.empty()) {
118119
a = "-C \"" + folder;
@@ -130,7 +131,7 @@ void Git::git(const std::string &folder, const std::string &args) {
130131
fixWindowsEnv();
131132
}
132133
#endif
133-
execCmd("git " + a);
134+
return execCmd("git " + a, fail_on_error);
134135
}
135136

136137
void Git::clone(const std::string &url, const std::string &folder) {

src/sys/git.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Git {
1111
static void fixWindowsEnv(std::string project_dir = "");
1212
#endif
1313

14-
static void git(const std::string &folder, const std::string &args);
14+
static bool git(const std::string &folder, const std::string &args,
15+
bool fail_on_error = true);
1516

1617
static void clone(const std::string &url, const std::string &folder);
1718

0 commit comments

Comments
 (0)