-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: use os.ReadDir
for lightweight directory reading
#2346
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2346 +/- ##
==========================================
- Coverage 53.66% 53.65% -0.01%
==========================================
Files 48 48
Lines 14201 14203 +2
==========================================
Hits 7621 7621
- Misses 6340 6342 +2
Partials 240 240
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR and for addressing the linting error. Looks good!
This commit also replaces the existing io/ioutil functions with their new definitions in io and os packages, since the io/ioutil package has been deprecated as of Go 1.16, see https://golang.org/doc/go1.16#ioutil. Reference: https://pkg.go.dev/io/ioutil#ReadDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
@@ -56,8 +58,11 @@ func getWorkerProcesses() (int, int, error) { | |||
continue | |||
} | |||
|
|||
cmdlineFile := fmt.Sprintf("/proc/%v/cmdline", folder.Name()) | |||
content, err := ioutil.ReadFile(cmdlineFile) | |||
cmdlineFile := filepath.Clean(fmt.Sprintf("/proc/%v/cmdline", folder.Name())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pleshakov Hi, thanks for reviewing this PR.
filepath.Clean
is necessary here to address the linting error, see this comment #2346 (comment)
Reference: golang/go#41467
Proposed changes
os.ReadDir
was added in Go 1.16 as part of the deprecation ofioutil
package. It is a more efficient implementation thanioutil.ReadDir
as stated here https://pkg.go.dev/io/ioutil#ReadDir . The full proposal can be read here: https://github.com/golang/go/issues/41467.This PR also replaces the existing io/ioutil functions with their new definitions in io and os packages, since the io/ioutil package has been deprecated as of Go 1.16, see https://golang.org/doc/go1.16#ioutil.
Checklist
Before creating a PR, run through this checklist and mark each as complete.