Skip to content
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

bugtool: simplify removeIfEmpty with more efficient os.ReadDir #24566

Merged
merged 1 commit into from Mar 28, 2023
Merged

bugtool: simplify removeIfEmpty with more efficient os.ReadDir #24566

merged 1 commit into from Mar 28, 2023

Conversation

Juneezee
Copy link
Contributor

  • For first time contributors, read Submitting a pull request
  • All code is covered by unit and/or runtime tests where feasible.
  • All commits contain a well written commit description including a title,
    description and a Fixes: #XXX line if the commit addresses a particular
    GitHub issue.
  • If your commit description contains a Fixes: <commit-id> tag, then
    please add the commit author[s] as reviewer[s] to this issue.
  • All commits are signed off. See the section Developer’s Certificate of Origin
  • Provide a title or release-note blurb suitable for the release notes.
  • Are you a user of Cilium? Please add yourself to the Users doc
  • Thanks for contributing!

We can simplify the following code

dir, err := os.Open(dirname)
if err != nil {
	return err
}
defer dir.Close()

dirs, err := dir.Readdir(-1)

with just os.ReadDir(dirname). os.ReadDir is recommended over Readdir(), as stated in the official doc 1

bugtool: simplify `removeIfEmpty` with more effiicient `os.ReadDir`

Footnotes

  1. https://pkg.go.dev/os#File.Readdir

We can simplify the following code
	dir, err := os.Open(dirname)
	if err != nil {
		return err
	}
	defer dir.Close()

	dirs, err := dir.Readdir(-1)

with just `os.ReadDir(dirname)`.

Reference: https://pkg.go.dev/os#ReadDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
@Juneezee Juneezee requested a review from a team as a code owner March 25, 2023 09:19
@Juneezee Juneezee requested a review from tklauser March 25, 2023 09:19
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Mar 25, 2023
@github-actions github-actions bot added the kind/community-contribution This was a contribution made by a community member. label Mar 25, 2023
@pchaigno pchaigno added kind/cleanup This includes no functional changes. area/bugtool Impacts gathering of data for debugging purposes. release-note/misc This PR makes changes that have no direct user impact. labels Mar 26, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Mar 26, 2023
@tklauser tklauser added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Mar 28, 2023
@julianwiedmann julianwiedmann merged commit e63d79b into cilium:master Mar 28, 2023
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bugtool Impacts gathering of data for debugging purposes. kind/cleanup This includes no functional changes. kind/community-contribution This was a contribution made by a community member. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants