Sort keys in image index to keep the digest consistent (#149)

The digest is calculated based on written json data, but JSONEncoder
doesn't preserve order bby default, so the digest is not consistent.

Signed-off-by: Alexey <makhov.alex@gmail.com>
This commit is contained in:
Alexey Makhov
2025-06-17 12:23:25 -07:00
committed by GitHub
parent 4a196b6dc2
commit 689af841d6
@@ -29,6 +29,8 @@ public class ContentWriter {
/// - base: The URL to write content to. If this is not a directory a
/// ContainerizationError will be thrown with a code of .internalError.
public init(for base: URL) throws {
self.encoder.outputFormatting = [JSONEncoder.OutputFormatting.sortedKeys]
self.base = base
var isDirectory = ObjCBool(true)
let exists = FileManager.default.fileExists(atPath: base.path, isDirectory: &isDirectory)