Skip to content

Commit

Permalink
Reformat whole project
Browse files Browse the repository at this point in the history
  • Loading branch information
Neloop committed Sep 25, 2020
1 parent 2c39585 commit 7ba5bf0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/config/sandbox_limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct sandbox_limits {
/**
* Return a mapping between dir_perm enums and their associated string representatives.
*/
static const std::map<sandbox_limits::dir_perm, std::string>& get_dir_perm_associated_strings()
static const std::map<sandbox_limits::dir_perm, std::string> &get_dir_perm_associated_strings()
{
static std::map<sandbox_limits::dir_perm, std::string> options;
if (options.size() == 0) {
Expand Down
10 changes: 5 additions & 5 deletions src/helpers/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,17 @@ std::vector<std::tuple<std::string, std::string, sandbox_limits::dir_perm>> help

if (mode & sandbox_limits::dir_perm::TMP) { // special checks for tmp
if (mode & sandbox_limits::dir_perm::FS) {
throw config_exception("Options 'fs' and 'tmp' are incompatible (they cannot be used together)");
throw config_exception(
"Options 'fs' and 'tmp' are incompatible (they cannot be used together)");
}
if (dir["src"]) {
throw config_exception("Path 'src' must not be present when mounting 'tmp' directory (only 'dst')");
throw config_exception(
"Path 'src' must not be present when mounting 'tmp' directory (only 'dst')");
}
}
}

if (dir["src"] && dir["src"].IsScalar()) {
dst = src = dir["src"].as<std::string>();
}
if (dir["src"] && dir["src"].IsScalar()) { dst = src = dir["src"].as<std::string>(); }
if (dir["dst"] && dir["dst"].IsScalar()) {
dst = dir["dst"].as<std::string>();
if (src.empty()) { src = dst; }
Expand Down
49 changes: 25 additions & 24 deletions src/helpers/string_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
#include "string_utils.h"
#include <cctype>

namespace {

void replace_substring(std::string &data, const std::string &from, const std::string &to)
namespace
{
std::size_t pos = data.find(from);
while(pos != std::string::npos) {
data.replace(pos, from.size(), to);
pos = data.find(from, pos + to.size());

void replace_substring(std::string &data, const std::string &from, const std::string &to)
{
std::size_t pos = data.find(from);
while (pos != std::string::npos) {
data.replace(pos, from.size(), to);
pos = data.find(from, pos + to.size());
}
}
}

void escape_regex(std::string &regex)
{
replace_substring(regex, "\\", "\\\\");
replace_substring(regex, "^", "\\^");
replace_substring(regex, ".", "\\.");
replace_substring(regex, "$", "\\$");
replace_substring(regex, "|", "\\|");
replace_substring(regex, "(", "\\(");
replace_substring(regex, ")", "\\)");
replace_substring(regex, "[", "\\[");
replace_substring(regex, "]", "\\]");
replace_substring(regex, "*", "\\*");
replace_substring(regex, "+", "\\+");
replace_substring(regex, "?", "\\?");
replace_substring(regex, "/", "\\/");
}
void escape_regex(std::string &regex)
{
replace_substring(regex, "\\", "\\\\");
replace_substring(regex, "^", "\\^");
replace_substring(regex, ".", "\\.");
replace_substring(regex, "$", "\\$");
replace_substring(regex, "|", "\\|");
replace_substring(regex, "(", "\\(");
replace_substring(regex, ")", "\\)");
replace_substring(regex, "[", "\\[");
replace_substring(regex, "]", "\\]");
replace_substring(regex, "*", "\\*");
replace_substring(regex, "+", "\\+");
replace_substring(regex, "?", "\\?");
replace_substring(regex, "/", "\\/");
}

} // namespace

Expand Down
12 changes: 3 additions & 9 deletions src/helpers/topological_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,14 @@ void helpers::topological_sort(std::shared_ptr<task_base> root, std::vector<std:
search_stack.pop_back();

// if visited, continue
if (visited.find(current->get_task_id()) != visited.end()) {
continue;
}
if (visited.find(current->get_task_id()) != visited.end()) { continue; }

// not visited, insert into queue
prior_queue.push(current);
visited.insert(current->get_task_id());

// go through children
for (auto &child : current->get_children()) {
search_stack.push_back(child);
}
for (auto &child : current->get_children()) { search_stack.push_back(child); }
}

// just to be sure, clear the search stack before using it
Expand Down Expand Up @@ -70,9 +66,7 @@ void helpers::topological_sort(std::shared_ptr<task_base> root, std::vector<std:

// not visited yet, make new priority queue of parents and fill it into stack
priority_queue_type task_queue;
for (auto &parent : current->get_parents()) {
task_queue.push(parent.lock());
}
for (auto &parent : current->get_parents()) { task_queue.push(parent.lock()); }
while (!task_queue.empty()) {
search_stack.push_back(task_queue.top());
task_queue.pop();
Expand Down
1 change: 0 additions & 1 deletion src/tasks/external_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ void external_task::sandbox_init()
limits.share_net = true; // initiation (compilation) tasks may use internet to download stuff

// TODO: a better way would be to make this optional (a job will define, whether it requires net or not)

}
sandbox_ = std::make_shared<isolate_sandbox>(
sandbox_config_, limits, worker_config_->get_worker_id(), temp_dir_, evaluation_dir_.string(), logger_);
Expand Down
33 changes: 15 additions & 18 deletions src/tasks/internal/dump_dir_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@
#include "dump_dir_task.h"
#include "helpers/string_utils.h"

namespace {
namespace
{

std::vector<std::regex> get_excludes(std::vector<std::string> &args) {
std::vector<std::string> excludesArgs(args.cbegin() + 3, args.cend());
std::vector<std::regex> excludes(args.size() - 3);
std::vector<std::regex> get_excludes(std::vector<std::string> &args)
{
std::vector<std::string> excludesArgs(args.cbegin() + 3, args.cend());
std::vector<std::regex> excludes(args.size() - 3);

for (auto &path : excludesArgs) {
excludes.push_back(helpers::wildcards_regex(path));
}
for (auto &path : excludesArgs) { excludes.push_back(helpers::wildcards_regex(path)); }

return excludes;
}
return excludes;
}

bool is_excluded(fs::path &relative_path, std::vector<std::regex> &excludes) {
for (auto &exclude : excludes) {
if (regex_match(relative_path.string(), exclude)) {
return true;
bool is_excluded(fs::path &relative_path, std::vector<std::regex> &excludes)
{
for (auto &exclude : excludes) {
if (regex_match(relative_path.string(), exclude)) { return true; }
}
return false;
}
return false;
}

} // namespace

Expand Down Expand Up @@ -63,9 +62,7 @@ std::shared_ptr<task_results> dump_dir_task::run()
auto dest_path = dest_root / relative_path;

// check if source path is excluded or not
if (is_excluded(path, excludes)) {
continue;
}
if (is_excluded(path, excludes)) { continue; }

if (!fs::exists(dest_path.parent_path())) {
auto return_code = make_dirs(dest_path.parent_path());
Expand Down

0 comments on commit 7ba5bf0

Please sign in to comment.