Skip to content

Commit dbc1128

Browse files
meisterTvmcj
authored andcommitted
Fix handling of binary files when editing executables. (#2043)
Fixes #1841. (cherry picked from commit 6e099ab)
1 parent 1ab0b57 commit dbc1128

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

webapp/src/Controller/Jury/ExecutableController.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,18 @@ public function viewAction(Request $request, string $execId): Response
241241
$this->em->persist($executableFile);
242242
$files[] = $executableFile;
243243
}
244+
$offset = count($files);
245+
foreach ($editorData['skippedBinary'] as $idx => $skippedBinaryData) {
246+
$origExecutableFile = $this->em->getRepository(ExecutableFile::class)->find($skippedBinaryData['execfileid']);
247+
$executableFile = new ExecutableFile();
248+
$executableFile
249+
->setRank($idx + $offset)
250+
->setIsExecutable($origExecutableFile->isExecutable())
251+
->setFilename($origExecutableFile->getFilename())
252+
->setFileContent($origExecutableFile->getFileContent());
253+
$this->em->persist($executableFile);
254+
$files[] = $executableFile;
255+
}
244256

245257
$immutableExecutable = new ImmutableExecutable($files);
246258
$this->em->persist($immutableExecutable);
@@ -436,7 +448,10 @@ protected function dataForEditor(Executable $executable): array
436448
$content = $file->getFileContent();
437449
$rank = $file->getRank();
438450
if (!mb_detect_encoding($content, null, true)) {
439-
$skippedBinary[] = $filename;
451+
$skippedBinary[] = [
452+
'filename' => $filename,
453+
'execfileid' => $file->getExecFileId(),
454+
];
440455
continue; // Skip binary files.
441456
}
442457
$filenames[] = $filename;

webapp/templates/jury/executable.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
<div class="alert alert-warning">
8383
We exclude these files from editing since we could not detect their encoding (e.g. they are binary files):
8484
<ul>
85-
{% for file in skippedBinary %}
86-
<li><code>{{ file }}</code></li>
85+
{% for data in skippedBinary %}
86+
<li><code>{{ data.filename }}</code></li>
8787
{% endfor %}
8888
</ul>
8989
</div>

0 commit comments

Comments
 (0)