From a02dbdbfa13d72fc53eb44dca3e3ef7c49b0ed9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Tue, 27 Sep 2022 21:19:46 +0200 Subject: [PATCH] Only touch lock files after successful JSON writes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AtomicWriteFile truly is atomic, it only changes the file on success. So there's no point notifying other processes about a changed file if we failed, they are going to see the same JSON data. Signed-off-by: Miloslav Trmač --- containers.go | 6 ++++-- images.go | 6 ++++-- layers.go | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/containers.go b/containers.go index 38d77e03f..4c3109e7f 100644 --- a/containers.go +++ b/containers.go @@ -243,8 +243,10 @@ func (r *containerStore) Save() error { if err != nil { return err } - defer r.Touch() - return ioutils.AtomicWriteFile(rpath, jdata, 0600) + if err := ioutils.AtomicWriteFile(rpath, jdata, 0600); err != nil { + return err + } + return r.Touch() } func newContainerStore(dir string) (ContainerStore, error) { diff --git a/images.go b/images.go index 508b85f63..f2c8bb004 100644 --- a/images.go +++ b/images.go @@ -324,8 +324,10 @@ func (r *imageStore) Save() error { if err != nil { return err } - defer r.Touch() - return ioutils.AtomicWriteFile(rpath, jdata, 0600) + if err := ioutils.AtomicWriteFile(rpath, jdata, 0600); err != nil { + return err + } + return r.Touch() } func newImageStore(dir string) (ImageStore, error) { diff --git a/layers.go b/layers.go index 5b6f4f9d5..c2f1ca748 100644 --- a/layers.go +++ b/layers.go @@ -501,8 +501,10 @@ func (r *layerStore) saveLayers() error { if err != nil { return err } - defer r.Touch() - return ioutils.AtomicWriteFile(rpath, jldata, 0600) + if err := ioutils.AtomicWriteFile(rpath, jldata, 0600); err != nil { + return err + } + return r.Touch() } func (r *layerStore) saveMounts() error {