mirror of
https://github.com/containers/podman.git
synced 2025-06-03 12:17:13 +08:00
machine config: make write atomic
As indicated in #21849, loading the machine config can flake/fail with an EOF JSON error indicating an incomplete file. Address the issue by atomically writing the config. This way, it is not possible to load an incomplete or partially written file. The lock can be acquired later on to sync state. [NO NEW TESTS NEEDED] as it's a hard-to-hit race. Fixes: #21849 Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
@ -16,6 +16,7 @@ import (
|
||||
"github.com/containers/podman/v5/pkg/machine/define"
|
||||
"github.com/containers/podman/v5/pkg/machine/lock"
|
||||
"github.com/containers/podman/v5/utils"
|
||||
"github.com/containers/storage/pkg/ioutils"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -133,7 +134,7 @@ func (mc *MachineConfig) write() error {
|
||||
return err
|
||||
}
|
||||
logrus.Debugf("writing configuration file %q", mc.configPath.Path)
|
||||
return os.WriteFile(mc.configPath.GetPath(), b, define.DefaultFilePerm)
|
||||
return ioutils.AtomicWriteFile(mc.configPath.GetPath(), b, define.DefaultFilePerm)
|
||||
}
|
||||
|
||||
func (mc *MachineConfig) SetRootful(rootful bool) error {
|
||||
|
Reference in New Issue
Block a user