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.
@@ -19,14 +19,19 @@ type PIDFile struct {
}
func checkPIDFileAlreadyExists(path string) error {
- if pidByte, err := os.ReadFile(path); err == nil {
+ 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
}
