|
1 | 1 | from __future__ import absolute_import
|
2 | 2 | import os
|
3 | 3 | import logging
|
4 |
| -from shutil import rmtree |
| 4 | +from shutil import copy2, rmtree |
5 | 5 | import tempfile
|
6 | 6 | from zipfile import ZipFile, is_zipfile
|
7 | 7 | from sio.executors.checker import _limit_length
|
8 | 8 | from sio.executors.common import _run_core
|
9 | 9 | from sio.workers import ft
|
10 | 10 | from sio.workers.executors import ExecError, PRootExecutor, UnprotectedExecutor
|
11 |
| -from sio.workers.util import decode_fields, replace_invalid_UTF, tempcwd |
| 11 | +from sio.workers.util import decode_fields, replace_invalid_UTF, tempcwd, TemporaryCwd |
12 | 12 | from sio.workers.file_runners import get_file_runner
|
13 | 13 |
|
14 |
| -# TODO XXX FIXME |
15 |
| -# Hide the files like enc_in or hint from the contestants |
16 |
| -# Would not be nice if someone just sideloaded enc_in in decoder |
17 |
| - |
18 | 14 | import six
|
19 | 15 |
|
20 | 16 | logger = logging.getLogger(__name__)
|
@@ -214,6 +210,23 @@ def _run_checker(environ, use_sandboxes=False):
|
214 | 210 | return False
|
215 | 211 |
|
216 | 212 |
|
| 213 | +def _run_decoder_hide_files(environ, file_executor, exe_filename, use_sandboxes, orig_dir): |
| 214 | + # We now have quite a lot of interes |
| 215 | + # be nice if some decoder read them. |
| 216 | + with TemporaryCwd() as new_dir: |
| 217 | + # Copy the executable and input |
| 218 | + for f in 'dec_in', exe_filename: |
| 219 | + copy2(os.path.join(orig_dir, f), tempcwd(f)) |
| 220 | + |
| 221 | + renv = _run_decoder(environ, file_executor, exe_filename, use_sandboxes) |
| 222 | + |
| 223 | + # Copy the output |
| 224 | + for f in 'dec_out',: |
| 225 | + copy2(tempcwd(f), os.path.join(orig_dir, f)) |
| 226 | + |
| 227 | + return renv |
| 228 | + |
| 229 | + |
217 | 230 | def run(environ, executor, use_sandboxes=True):
|
218 | 231 | """
|
219 | 232 | Common code for executors.
|
@@ -244,7 +257,7 @@ def run(environ, executor, use_sandboxes=True):
|
244 | 257 | if not _run_channel(environ, use_sandboxes):
|
245 | 258 | return environ
|
246 | 259 |
|
247 |
| - renv = _run_decoder(environ, file_executor, exe_filename, use_sandboxes) |
| 260 | + renv = _run_decoder_hide_files(environ, file_executor, exe_filename, use_sandboxes, tempcwd()) |
248 | 261 | _populate_environ(renv, environ, "decoder_")
|
249 | 262 |
|
250 | 263 | if renv["result_code"] != "OK":
|
|
0 commit comments