diff --git a/src/config/sandbox_limits.h b/src/config/sandbox_limits.h index 2e698697..78615788 100644 --- a/src/config/sandbox_limits.h +++ b/src/config/sandbox_limits.h @@ -32,7 +32,7 @@ struct sandbox_limits { /** * Return a mapping between dir_perm enums and their associated string representatives. */ - static const std::map& get_dir_perm_associated_strings() + static const std::map &get_dir_perm_associated_strings() { static std::map options; if (options.size() == 0) { diff --git a/src/helpers/config.cpp b/src/helpers/config.cpp index ee04a5e3..c139e5b8 100644 --- a/src/helpers/config.cpp +++ b/src/helpers/config.cpp @@ -279,17 +279,17 @@ std::vector> 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(); - } + if (dir["src"] && dir["src"].IsScalar()) { dst = src = dir["src"].as(); } if (dir["dst"] && dir["dst"].IsScalar()) { dst = dir["dst"].as(); if (src.empty()) { src = dst; } diff --git a/src/helpers/string_utils.cpp b/src/helpers/string_utils.cpp index 1390127c..92cb1999 100644 --- a/src/helpers/string_utils.cpp +++ b/src/helpers/string_utils.cpp @@ -1,33 +1,34 @@ #include "string_utils.h" #include -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 ®ex) -{ - 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 ®ex) + { + 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 diff --git a/src/helpers/topological_sort.cpp b/src/helpers/topological_sort.cpp index 4d391861..e4433884 100644 --- a/src/helpers/topological_sort.cpp +++ b/src/helpers/topological_sort.cpp @@ -31,18 +31,14 @@ void helpers::topological_sort(std::shared_ptr root, std::vectorget_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 @@ -70,9 +66,7 @@ void helpers::topological_sort(std::shared_ptr root, std::vectorget_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(); diff --git a/src/tasks/external_task.cpp b/src/tasks/external_task.cpp index ce689ea7..fa9cb011 100644 --- a/src/tasks/external_task.cpp +++ b/src/tasks/external_task.cpp @@ -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( sandbox_config_, limits, worker_config_->get_worker_id(), temp_dir_, evaluation_dir_.string(), logger_); diff --git a/src/tasks/internal/dump_dir_task.cpp b/src/tasks/internal/dump_dir_task.cpp index d6b4a162..dd09c255 100644 --- a/src/tasks/internal/dump_dir_task.cpp +++ b/src/tasks/internal/dump_dir_task.cpp @@ -2,27 +2,26 @@ #include "dump_dir_task.h" #include "helpers/string_utils.h" -namespace { +namespace +{ -std::vector get_excludes(std::vector &args) { - std::vector excludesArgs(args.cbegin() + 3, args.cend()); - std::vector excludes(args.size() - 3); + std::vector get_excludes(std::vector &args) + { + std::vector excludesArgs(args.cbegin() + 3, args.cend()); + std::vector 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 &excludes) { - for (auto &exclude : excludes) { - if (regex_match(relative_path.string(), exclude)) { - return true; + bool is_excluded(fs::path &relative_path, std::vector &excludes) + { + for (auto &exclude : excludes) { + if (regex_match(relative_path.string(), exclude)) { return true; } } + return false; } - return false; -} } // namespace @@ -63,9 +62,7 @@ std::shared_ptr 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());