Skip to content

Commit 689af84

Browse files
authored
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>
1 parent 4a196b6 commit 689af84

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Sources/ContainerizationOCI/Content/ContentWriter.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class ContentWriter {
2929
/// - base: The URL to write content to. If this is not a directory a
3030
/// ContainerizationError will be thrown with a code of .internalError.
3131
public init(for base: URL) throws {
32+
self.encoder.outputFormatting = [JSONEncoder.OutputFormatting.sortedKeys]
33+
3234
self.base = base
3335
var isDirectory = ObjCBool(true)
3436
let exists = FileManager.default.fileExists(atPath: base.path, isDirectory: &isDirectory)

0 commit comments

Comments
 (0)