open($temporary, ZipArchive::CREATE | ZipArchive::EXCL) !== true) { throw new LogicException('Private archive creation failed.'); } foreach (['manifest.json', ...array_keys($manifest['files'])] as $file) { if (! $zip->addFile($root.'/'.$file, $file) || ! $zip->setMtimeName($file, 1795910400) || ! $zip->setExternalAttributesName($file, ZipArchive::OPSYS_UNIX, 0100644 << 16)) { throw new LogicException('Private archive entry failed.'); } } if (! $zip->close()) { throw new LogicException('Private archive close failed.'); } $hash = hash_file('sha256', $temporary); if (is_file($target)) { if (is_link($target) || ! hash_equals($hash, hash_file('sha256', $target))) { throw new LogicException('Existing archive differs; replacement refused.'); } } elseif (! rename($temporary, $target)) { throw new LogicException('Private archive publication failed.'); } echo json_encode(['state' => 'private_candidate_only', 'archive' => $target, 'entries' => 4, 'manifest_sha256' => InventoryConversionRuntime::MANIFEST_SHA256, 'archive_sha256' => $hash, 'pilot_or_production_changes' => false], JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT).PHP_EOL; } finally { if (is_file($temporary)) { unlink($temporary); } }