fix(git): check destination emptiness without full readdir#1141
Open
AdeshDeshmukh wants to merge 1 commit intokitops-ml:mainfrom
Open
fix(git): check destination emptiness without full readdir#1141AdeshDeshmukh wants to merge 1 commit intokitops-ml:mainfrom
AdeshDeshmukh wants to merge 1 commit intokitops-ml:mainfrom
Conversation
Member
|
Can you add the sign-off messages to your commits. Click on the failing DCO check above for how to instructions. |
Contributor
There was a problem hiding this comment.
Pull request overview
Improves clone destination validation in the Git external helper by checking whether the destination directory is empty without reading the entire directory listing, reducing unnecessary I/O for large directories.
Changes:
- Replace
os.ReadDir(path)full directory reads withos.Open(path)+ReadDir(1)to detect emptiness. - Add
ioimport to handleio.EOFfrom the one-entry probe and preserve existing error semantics.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
@AdeshDeshmukh please fix failing DCO check before we can review this. |
Avoid reading an entire directory just to determine if clone destination is empty. Use ReadDir(1) to detect emptiness efficiently while preserving error behavior for non-empty and inaccessible paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: AdeshDeshmukh <adeshkd123@gmail.com>
5dcdb18 to
253d087
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Avoid reading an entire directory just to determine if clone destination is empty. Use ReadDir(1) to detect emptiness efficiently while preserving error behavior for non-empty and inaccessible paths.
Description
This PR improves clone destination validation in
pkg/lib/external/git/clone.go.Previously,
checkDestinationusedos.ReadDir(path)to determine whether a directory is empty, which reads the entire directory contents even though only an empty/non-empty check is needed.This change replaces that with a one-entry probe:
os.Open(path)ReadDir(1)Behavior is preserved:
err == nil=> directory is non-emptyerr == io.EOF=> directory is emptyValidation:
go test ./pkg/lib/external/git(pass)Linked issues
N/A