Skip to content

Commit

Permalink
Compute hashes of executable files when migrating
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tom93 committed Jul 28, 2024
1 parent 5c96eb0 commit f62d0ec
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions webapp/migrations/Version20230508163415.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ final class Version20230508163415 extends AbstractMigration
{
public function getDescription(): string
{
return 'Update hashes of immutable executables';
return 'Update hashes of executable files and immutable executables';
}

public function up(Schema $schema): void
{
$executableFiles = $this->connection->fetchAllAssociative('SELECT execfileid, file_content FROM executable_file');
foreach ($executableFiles as $file) {
$this->connection->executeStatement('UPDATE executable_file SET hash = :hash WHERE execfileid = :id', [
'hash' => md5($file['file_content']),
'id' => $file['execfileid']
]);
}
$immutableExecutables = $this->connection->fetchAllAssociative('SELECT immutable_execid FROM immutable_executable');
foreach ($immutableExecutables as $immutableExecutable) {
$files = $this->connection->fetchAllAssociative('SELECT hash, filename, is_executable FROM executable_file WHERE immutable_execid = :id', ['id' => $immutableExecutable['immutable_execid']]);
Expand All @@ -32,7 +39,7 @@ public function up(Schema $schema): void
)
)
);
$this->connection->executeQuery('UPDATE immutable_executable SET hash = :hash WHERE immutable_execid = :id', [
$this->connection->executeStatement('UPDATE immutable_executable SET hash = :hash WHERE immutable_execid = :id', [
'hash' => $newHash,
'id' => $immutableExecutable['immutable_execid'],
]);
Expand Down

0 comments on commit f62d0ec

Please sign in to comment.