Skip to content

Commit 55d1dc9

Browse files
authored
ImageStore: write state.json atomically (#835)
save() encodes into state.json in place, so a concurrent reader can observe a truncated or garbled file.
1 parent fc2b9bd commit 55d1dc9

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

Sources/Containerization/Image/ImageStore/ImageStore+ReferenceManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension ImageStore {
4949

5050
private func save(_ state: State) throws {
5151
let statePath = self.path.appendingPathComponent("state.json")
52-
try JSONEncoder().encode(state).write(to: statePath)
52+
try JSONEncoder().encode(state).write(to: statePath, options: .atomic)
5353
}
5454

5555
public func delete(reference: String) throws {

0 commit comments

Comments
 (0)