Skip to content

Commit

Permalink
Better name of the working_dir variable which is inside sandbox. Tune…
Browse files Browse the repository at this point in the history
… up a bit exception messages for relativeness.
  • Loading branch information
Neloop committed May 10, 2018
1 parent 2080d5a commit 1d19a02
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/job/job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ job::~job()
void job::check_job_dirs()
{
// initialize default working directory inside sandbox
working_path_ = fs::path("/box");
sandbox_working_path_ = fs::path("/box");

if (!fs::exists(temporary_directory_)) {
throw job_exception("Working directory not exists");
Expand Down Expand Up @@ -135,7 +135,8 @@ void job::build_job()

// check relativeness of working directory
if (!helpers::check_relative(fs::path(sandbox->working_directory))) {
throw job_exception("Given working directory for task '" + task_meta->task_id + "' is not relative");
throw job_exception(
"Given working directory for task '" + task_meta->task_id + "' is not relative or contains '..'");
}

// go through variables parsing
Expand All @@ -160,7 +161,7 @@ void job::build_job()
logger_,
temporary_directory_.string(),
source_path_,
working_path_};
sandbox_working_path_};

task = factory_->create_sandboxed_task(data);

Expand Down Expand Up @@ -440,7 +441,7 @@ void job::prepare_job_vars()
{"JOB_ID", job_meta_->job_id},
{"SOURCE_DIR", source_path_.string()},
{"RESULT_DIR", result_path_.string()},
{"EVAL_DIR", working_path_.string()},
{"EVAL_DIR", sandbox_working_path_.string()},
{"TEMP_DIR", fs::temp_directory_path().string()},
{"JUDGES_DIR", fs::path("/usr/bin").string()}};

Expand Down
2 changes: 1 addition & 1 deletion src/job/job.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class job
/** Directory where results and log of job are stored. */
fs::path result_path_;
/** Directory inside sandbox which should be bound as the working one. */
fs::path working_path_;
fs::path sandbox_working_path_;
/** Factory for creating tasks. */
std::shared_ptr<task_factory_interface> factory_;
/** Progress callback which is called on some important points */
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/create_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct create_params {
/** directory where source files given by users are located */
fs::path source_path;
/** working directory which points inside sandbox */
fs::path working_path;
fs::path sandbox_working_path;
};


Expand Down
8 changes: 4 additions & 4 deletions src/tasks/external_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace fs = boost::filesystem;
external_task::external_task(const create_params &data)
: task_base(data.id, data.task_meta), worker_config_(data.worker_conf), sandbox_(nullptr),
sandbox_config_(data.task_meta->sandbox), limits_(data.limits), logger_(data.logger), temp_dir_(data.temp_dir),
evaluation_dir_(data.source_path), working_dir_(data.working_path)
evaluation_dir_(data.source_path), sandbox_working_dir_(data.sandbox_working_path)
{
if (worker_config_ == nullptr) {
throw task_exception("No worker configuration provided.");
Expand All @@ -29,7 +29,7 @@ external_task::external_task(const create_params &data)

if (!sandbox_config_->working_directory.empty()) {
if (!helpers::check_relative(sandbox_config_->working_directory)) {
throw task_exception("Given working directory in sandbox config is not relative");
throw task_exception("Given working directory in sandbox config is not relative or contains '..'");
}

evaluation_dir_ = fs::path(data.source_path) / sandbox_config_->working_directory;
Expand Down Expand Up @@ -124,7 +124,7 @@ void external_task::results_output_init()
if (sandbox_config_->std_output == "") {
remove_stdout_ = true;
std::string stdout_file = task_meta_->task_id + "." + random + ".output.stdout";
sandbox_config_->std_output = (working_dir_ / fs::path(stdout_file)).string();
sandbox_config_->std_output = (sandbox_working_dir_ / fs::path(stdout_file)).string();
}
}

Expand All @@ -133,7 +133,7 @@ void external_task::results_output_init()
if (sandbox_config_->std_error == "") {
remove_stderr_ = true;
std::string stderr_file = task_meta_->task_id + "." + random + ".output.stderr";
sandbox_config_->std_error = (working_dir_ / fs::path(stderr_file)).string();
sandbox_config_->std_error = (sandbox_working_dir_ / fs::path(stderr_file)).string();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/external_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class external_task : public task_base
/** Directory outside sandbox where task will be executed */
fs::path evaluation_dir_;
/** Directory binded to the sandbox as default working dir */
fs::path working_dir_;
fs::path sandbox_working_dir_;
/** After execution delete stdout file produced by sandbox */
bool remove_stdout_ = false;
/** After execution delete stderr file produced by sandbox */
Expand Down

0 comments on commit 1d19a02

Please sign in to comment.