attempt to re-download demos with invalid hash

This commit is contained in:
Robin Appelman 2018-02-24 12:16:16 +01:00
commit 9fd4b88d8d

View file

@ -24,7 +24,7 @@ class Migrate {
$hash = $this->store->hash($name); $hash = $this->store->hash($name);
if ($hash !== $demo['hash']) { if ($hash !== $demo['hash']) {
throw new \Exception('hash mismatch: ' . $this->store->generatePath($name)); $this->reDownloadDemo($demo);
} }
return $this->api->changeDemo( return $this->api->changeDemo(
@ -36,4 +36,19 @@ class Migrate {
$this->key $this->key
); );
} }
private function reDownloadDemo(array $demo) {
$name = basename($demo['url']);
$tmpFile = tempnam(sys_get_temp_dir(), 'dem_');
copy($demo['url'], $tmpFile);
$newHash = md5_file($tmpFile);
if ($newHash !== $demo['hash']) {
throw new \Exception('hash mismatch even after re-download: ' . $this->store->generatePath($name));
}
unlink($this->store->generatePath($name));
rename($tmpFile, $this->store->generatePath($name));
}
} }