mirror of
https://github.com/containers/podman.git
synced 2025-06-02 02:26:52 +08:00
container/pod id file: truncate instead of throwing an error
Truncate the container and pod ID files instead of throwing an error. The main motivation is to prevent redundant work when starting systemd units. Throwing an error when the file already exists is not preventing races or file corruptions, so let's leave that to the user which in almost all cases are generated (and tested) systemd units. Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
@ -682,18 +682,15 @@ func DefaultContainerConfig() *config.Config {
|
||||
return containerConfig
|
||||
}
|
||||
|
||||
func CreateCidFile(cidfile string, id string) error {
|
||||
cidFile, err := OpenExclusiveFile(cidfile)
|
||||
func CreateIDFile(path string, id string) error {
|
||||
idFile, err := os.Create(path)
|
||||
if err != nil {
|
||||
if os.IsExist(err) {
|
||||
return fmt.Errorf("container id file exists. Ensure another container is not using it or delete %s", cidfile)
|
||||
}
|
||||
return fmt.Errorf("opening cidfile %s", cidfile)
|
||||
return fmt.Errorf("creating idfile: %w", err)
|
||||
}
|
||||
if _, err = cidFile.WriteString(id); err != nil {
|
||||
logrus.Error(err)
|
||||
defer idFile.Close()
|
||||
if _, err = idFile.WriteString(id); err != nil {
|
||||
return fmt.Errorf("writing idfile: %w", err)
|
||||
}
|
||||
cidFile.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user