fix(git): check destination emptiness without full readdir#1141
fix(git): check destination emptiness without full readdir#1141AdeshDeshmukh wants to merge 1 commit into
Conversation
|
Can you add the sign-off messages to your commits. Click on the failing DCO check above for how to instructions. |
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.
|
@AdeshDeshmukh please fix failing DCO check before we can review this. |
5dcdb18 to
253d087
Compare
amisevsk
left a comment
There was a problem hiding this comment.
Please reduce this changeset to only address the issue mentioned in the PR title; changing annotations used by Kit and adding legacy options should be done in a separate PR (personally I don't think this is very high priority at the moment).
Also, there are merge conflicts that need to be addressed.
| // KitOps-specific annotations for ModelKit artifacts. | ||
| // Canonical keys use the reverse-DNS form of kitops.org. | ||
| CliVersionAnnotation = "org.kitops.modelkit.cli-version" | ||
| KitfileJsonAnnotation = "org.kitops.modelkit.kitfile" | ||
|
|
||
| // Legacy annotation keys kept for backwards compatibility when reading/writing | ||
| // manifests produced by older CLI versions. | ||
| LegacyCliVersionAnnotation = "ml.kitops.modelkit.cli-version" | ||
| LegacyKitfileJsonAnnotation = "ml.kitops.modelkit.kitfile" | ||
|
|
||
| // LayerSubtypeAnnotation stores additional type information for a given OCI manifest | ||
| // layer within its annotations (e.g. storing prompts within code-type layers) | ||
| LayerSubtypeAnnotation = "ml.kitops.modelkit.layer-subtype" | ||
| LayerSubtypePrompt = "prompt" | ||
| LayerSubtypeAnnotation = "org.kitops.modelkit.layer-subtype" | ||
| LegacyLayerSubtypeAnnotation = "ml.kitops.modelkit.layer-subtype" | ||
| LayerSubtypePrompt = "prompt" |
There was a problem hiding this comment.
This change, while generally something we probably should do, is unrelated to the purpose of this PR and should be broken out into a separate PR.
Additionally, it adds a decent amount of complexity for handling annotations; I think we're fine sticking with the ml prefix for now.
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. Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
253d087 to
5954401
Compare
|
@amisevsk Thank you for your thorough review and valuable suggestions. I've removed the annotation migration changes as you recommended — the PR now focuses solely on the clone.go directory emptiness check. I've also resolved the merge conflicts and ensured DCO compliance. Would appreciate a re-review when you a bandwidth. PTAL |
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