pkg/pidfile: don't ignore all errors when reading file
It's ok to ignore if the file doesn't exist, or if the file doesn't have a PID in it, but we should produce an error if the file exists, but we're unable to read it for other reasons. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
3ce2a7d026
commit
4917bcc039
1 changed files with 11 additions and 6 deletions
|
@ -19,12 +19,17 @@ type PIDFile struct {
|
|||
}
|
||||
|
||||
func checkPIDFileAlreadyExists(path string) error {
|
||||
if pidByte, err := os.ReadFile(path); err == nil {
|
||||
pidString := strings.TrimSpace(string(pidByte))
|
||||
if pid, err := strconv.Atoi(pidString); err == nil {
|
||||
if processExists(pid) {
|
||||
return fmt.Errorf("pid file found, ensure docker is not running or delete %s", path)
|
||||
}
|
||||
pidByte, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
pidString := strings.TrimSpace(string(pidByte))
|
||||
if pid, err := strconv.Atoi(pidString); err == nil {
|
||||
if processExists(pid) {
|
||||
return fmt.Errorf("pid file found, ensure docker is not running or delete %s", path)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Add table
Reference in a new issue