pkg/pidfile: reduce cyclomatic complexity, and small optimisation
Use bytes.TrimSpace instead of using the strings package, which is more performant, and allows us to skip the intermediate variable. Also combined some "if" statements to reduce cyclomatic complexity. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
4917bcc039
commit
dd8983f96c
|
@ -4,11 +4,11 @@
|
||||||
package pidfile // import "github.com/docker/docker/pkg/pidfile"
|
package pidfile // import "github.com/docker/docker/pkg/pidfile"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
)
|
)
|
||||||
|
@ -26,12 +26,10 @@ func checkPIDFileAlreadyExists(path string) error {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pidString := strings.TrimSpace(string(pidByte))
|
pid, err := strconv.Atoi(string(bytes.TrimSpace(pidByte)))
|
||||||
if pid, err := strconv.Atoi(pidString); err == nil {
|
if err == nil && processExists(pid) {
|
||||||
if processExists(pid) {
|
|
||||||
return fmt.Errorf("pid file found, ensure docker is not running or delete %s", path)
|
return fmt.Errorf("pid file found, ensure docker is not running or delete %s", path)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue