Only touch lock files after successful JSON writes

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č <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač 2022-09-27 21:19:46 +02:00
parent fb2df5d9fd
commit a02dbdbfa1
3 changed files with 12 additions and 6 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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 {