-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Replace walk with walkdir #34251
base: master
Are you sure you want to change the base?
Replace walk with walkdir #34251
Conversation
Hi @priyanshikhetwani. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: priyanshikhetwani The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hey use fs.DirEntry instead of os.DirEntry. |
@@ -223,7 +223,7 @@ func (t *GinkgoTester) findBinary(name string) (string, error) { | |||
} | |||
|
|||
if bazelBinExists { | |||
err := filepath.Walk(bazelBin, func(path string, info os.FileInfo, err error) error { | |||
err := filepath.WalkDir(bazelBin, func(path string, info os.DirEntry, err error) error { |
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.
This tool is deprecated but at the same time breaking it would be a problem.
Do we really need to make this change?
Go does not remove or stop supporting deprecated methods in the standard library (this would break the Go1 promise), they just discourage new usage versus better designed utilities.
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.
The aim was to remove overhead calls to os.stat since filepath.WalkDir
allows us to interact with directory entries directly via os.DirEntry without needing to gather full file metadata (size, permissions, etc) , which avoids the overhead of making an additional system call (os.Stat) for each file.
But if this would break the Go1 promise, Do you want me to close this PR?
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.
The aim was to remove overhead calls to os.stat since filepath.WalkDir allows us to interact with directory entries directly via os.DirEntry without needing to gather full file metadata (size, permissions, etc) , which avoids the overhead of making an additional system call (os.Stat) for each file.
This overhead is negligible though, isn't it? This isn't a high performance operation (also this particular codepath is effectively dead unless developing very old kubernetes releases)
But if this would break the Go1 promise, Do you want me to close this PR?
Er no, Go cannot remove the old method, so continuing to use it is safe. Us switching to a different API just requires not introducing our own bugs.
What would you like to be added:
filepath.WalkDir where its appropriate.
Why is this needed:
To reduce unnecessary stat call.
(filepath.WalkDir uses os.DirEntry, which is more lightweight and avoids redundant stat calls, making it faster and more efficient for traversing directories when full metadata is not needed.)
Fixes: #34250