2013-01-07 00:45:11 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
2023-02-12 18:24:56 +00:00
|
|
|
// Copyright (C) 2023 University of California
|
2013-01-07 00:45:11 +00:00
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-06-24 22:42:11 +00:00
|
|
|
// functions for initiating deletion of sticky files on clients.
|
|
|
|
// The project can supply a file "file_delete_regex"
|
|
|
|
// which is a list of regular expressions for names of files to be deleted.
|
|
|
|
|
2013-01-07 00:45:11 +00:00
|
|
|
#include <regex.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <vector>
|
2013-01-22 03:59:36 +00:00
|
|
|
#include <string>
|
2013-01-07 00:45:11 +00:00
|
|
|
|
2013-01-22 03:59:36 +00:00
|
|
|
#include "sched_config.h"
|
2013-01-07 00:45:11 +00:00
|
|
|
#include "sched_msgs.h"
|
|
|
|
#include "sched_types.h"
|
|
|
|
#include "str_util.h"
|
|
|
|
|
|
|
|
#include "sched_files.h"
|
|
|
|
|
2013-01-22 03:59:36 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
vector<regex_t> file_delete_regex;
|
|
|
|
vector<string> file_delete_regex_string;
|
2013-01-07 00:45:11 +00:00
|
|
|
|
|
|
|
int init_file_delete_regex() {
|
|
|
|
char buf[256];
|
2023-02-12 18:24:56 +00:00
|
|
|
FILE* f = boinc::fopen("../file_delete_regex", "r");
|
2013-01-17 22:34:04 +00:00
|
|
|
|
2013-01-07 00:45:11 +00:00
|
|
|
if (!f) return 0;
|
2023-02-12 18:24:56 +00:00
|
|
|
while (boinc::fgets(buf, sizeof(buf), f)) {
|
2013-01-07 00:45:11 +00:00
|
|
|
strip_whitespace(buf);
|
|
|
|
if (!strlen(buf)) continue;
|
|
|
|
regex_t re;
|
|
|
|
if (regcomp(&re, buf, REG_EXTENDED|REG_NOSUB)) {
|
|
|
|
log_messages.printf(MSG_CRITICAL,
|
|
|
|
"invalid regular expression in file_delete_regex: %s\n", buf
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
file_delete_regex.push_back(re);
|
2013-01-22 03:59:36 +00:00
|
|
|
file_delete_regex_string.push_back(string(buf));
|
2013-01-07 00:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-12 18:24:56 +00:00
|
|
|
boinc::fclose(f);
|
2013-01-07 00:45:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int do_file_delete_regex() {
|
|
|
|
for (unsigned int i=0; i<g_request->file_infos.size(); i++) {
|
|
|
|
FILE_INFO& fi = g_request->file_infos[i];
|
2013-01-22 03:59:36 +00:00
|
|
|
bool found = false;
|
2013-01-07 00:45:11 +00:00
|
|
|
for (unsigned int j=0; j<file_delete_regex.size(); j++) {
|
|
|
|
regex_t& re = file_delete_regex[j];
|
2013-12-19 00:33:14 +00:00
|
|
|
if (!regexec(&re, fi.name, 0, NULL, 0)) {
|
2013-01-07 00:45:11 +00:00
|
|
|
g_reply->file_deletes.push_back(fi);
|
2013-01-22 03:59:36 +00:00
|
|
|
if (config.debug_client_files) {
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
2013-01-23 07:51:02 +00:00
|
|
|
"[client_files] Sticky file %s matched regex %s; deleting\n",
|
2013-01-23 18:41:19 +00:00
|
|
|
fi.name, file_delete_regex_string[j].c_str()
|
2013-01-22 03:59:36 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
found = true;
|
2013-01-07 00:45:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-22 03:59:36 +00:00
|
|
|
if (config.debug_client_files && !found) {
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
2013-01-23 07:51:02 +00:00
|
|
|
"[client_files] Sticky file %s didn't match any regex\n", fi.name
|
2013-01-22 03:59:36 +00:00
|
|
|
);
|
|
|
|
}
|
2013-01-07 00:45:11 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|