Skip to content

Commit 34ac5e3

Browse files
committed
Compute hashes of executable files when migrating
The 'hash' column was added in commit bc1608f (Add hash to executable files and immutable executables., 2021-03-30), but the hashes were not computed for existing files, which breaks migrations from < 8.0.0 (judging fails with error message "Fetching executable failed for compile script '<n>': Unexpected hash ..."). This commit adds the code to an existing migration (Version20230508163415, added in DOMjudge 8.3.0) because the code in that migration uses the file hashes and won't work if they haven't been computed. Users who already performed an upgrade from 7.x to 8.3.0 will need to manually re-run that migration: bin/console doctrine:migrations:execute 'DoctrineMigrations\Version20230508163415' --down bin/console doctrine:migrations:execute 'DoctrineMigrations\Version20230508163415' --up
1 parent 5c96eb0 commit 34ac5e3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

webapp/migrations/Version20230508163415.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ final class Version20230508163415 extends AbstractMigration
1515
{
1616
public function getDescription(): string
1717
{
18-
return 'Update hashes of immutable executables';
18+
return 'Update hashes of executable files and immutable executables';
1919
}
2020

2121
public function up(Schema $schema): void
2222
{
23+
$executableFiles = $this->connection->fetchAllAssociative('SELECT execfileid, file_content FROM executable_file');
24+
foreach ($executableFiles as $file) {
25+
$this->connection->executeQuery('UPDATE executable_file SET hash = :hash WHERE execfileid = :id', [
26+
'hash' => md5($file['file_content']),
27+
'id' => $file['execfileid']
28+
]);
29+
}
2330
$immutableExecutables = $this->connection->fetchAllAssociative('SELECT immutable_execid FROM immutable_executable');
2431
foreach ($immutableExecutables as $immutableExecutable) {
2532
$files = $this->connection->fetchAllAssociative('SELECT hash, filename, is_executable FROM executable_file WHERE immutable_execid = :id', ['id' => $immutableExecutable['immutable_execid']]);
@@ -32,7 +39,7 @@ public function up(Schema $schema): void
3239
)
3340
)
3441
);
35-
$this->connection->executeQuery('UPDATE immutable_executable SET hash = :hash WHERE immutable_execid = :id', [
42+
$this->connection->executeStatement('UPDATE immutable_executable SET hash = :hash WHERE immutable_execid = :id', [
3643
'hash' => $newHash,
3744
'id' => $immutableExecutable['immutable_execid'],
3845
]);

0 commit comments

Comments
 (0)