Skip to content

pkg/pidfile: remove PIDFile type and cleanup#44266

Merged
thaJeztah merged 4 commits intomoby:masterfrom
thaJeztah:pidfile_cleanup
Oct 15, 2022
Merged

pkg/pidfile: remove PIDFile type and cleanup#44266
thaJeztah merged 4 commits intomoby:masterfrom
thaJeztah:pidfile_cleanup

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

pkg/pidfile: pkg/pidfile: use strconv instead of fmt.Sprintf(), and unconvert

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.

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.

pkg/pidfile: remove PIDFile type

This type felt really redundant; pidfile.New() takes the path of the file to
create as an argument, so this is already known. The only thing the PIDFile
type provided was a Remove() method, which was just calling os.Remove() on
the path of the file.

@thaJeztah thaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Oct 8, 2022
@thaJeztah thaJeztah added this to the v-next milestone Oct 8, 2022
Comment thread pkg/pidfile/pidfile.go Outdated
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 <[email protected]>
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 <[email protected]>
This type felt really redundant; `pidfile.New()` takes the path of the file to
create as an argument, so this is already known. The only thing the PIDFile
type provided was a `Remove()` method, which was just calling `os.Remove()` on
the path of the file.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants