GeezerVison is showing github.com — fix scandir/lstat for windows by youknowone · Pull Request #6357 · RustPython/RustPython
Conversation
youknowone
commented
Dec 8, 2025
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary by CodeRabbit
-
Bug Fixes
- Improved file system directory scanning performance on Windows through optimized metadata handling.
-
Refactor
- Updated lstat() function signature to accept file paths only instead of file paths or file descriptors.
✏️ Tip: You can customize this high-level summary in your review settings.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Dec 8, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Walkthrough
Changes to crates/vm/src/stdlib/os.rs optimize Windows directory iteration by pre-caching lstat metadata in DirEntry objects using OnceCell. The public lstat function signature changed from accepting OsPathOrFd<'_> to OsPath, with implementation forwarding to stat with FollowSymlinks(false). Platform-conditional cache initialization handles Windows and non-Windows paths separately.
Changes
| Cohort / File(s) |
Summary |
Windows lstat pre-caching in directory iteration crates/vm/src/stdlib/os.rs |
Introduced Windows-specific pre-caching of lstat data during scandir iteration via win32_xstat metadata, storing result in OnceCell per entry. DirEntry construction now uses locally computed pathval and assigns pre-cached lstat cell. Non-Windows platforms initialize lstat as empty OnceCell. Public lstat function signature changed from OsPathOrFd<'_> to OsPath, with call forwarding to stat(..., FollowSymlinks(false), vm). |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Areas requiring extra attention:
- Public API signature change for
lstat(): verify all call sites are compatible with the new OsPath-only parameter
- Windows-specific pre-caching logic: ensure win32_xstat integration correctly populates OnceCell and handles edge cases (removed files, permission errors)
- Platform-conditional initialization: confirm non-Windows codepaths maintain original OnceCell behavior and performance characteristics
- DirEntry construction: validate that pre-cached vs. empty lstat assignments don't introduce cache inconsistencies or memory leaks
Possibly related PRs
Poem
🐰 Hops through Windows paths with glee,
Caching stat before it's free,
OnceCell guards the metadata's keep,
While scandir's cache runs swift and deep! ✨
Pre-merge checks and finishing touches
✅ Passed checks (3 passed)
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
✅ Passed |
The title directly describes the main changes: fixing scandir/lstat functionality for Windows platform. |
| Docstring Coverage |
✅ Passed |
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
✨ Finishing touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
📜 Recent review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between abfd148 and 207a456.
⛔ Files ignored due to path filters (1)
Lib/test/test_os.py is excluded by !Lib/**
📒 Files selected for processing (1)
crates/vm/src/stdlib/os.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by running cargo fmt to format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/vm/src/stdlib/os.rs
🧠 Learnings (3)
📓 Common learnings
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration using #ifdef checks rather than providing fallback values for other platforms.
📚 Learning: 2025-06-27T14:47:28.810Z
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration using #ifdef checks rather than providing fallback values for other platforms.
Applied to files:
crates/vm/src/stdlib/os.rs
📚 Learning: 2025-06-27T14:47:28.810Z
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration rather than providing fallback values for other platforms.
Applied to files:
crates/vm/src/stdlib/os.rs
🧬 Code graph analysis (1)
crates/vm/src/stdlib/os.rs (1)
crates/vm/src/windows.rs (1)
🔇 Additional comments (3)
crates/vm/src/stdlib/os.rs (3)
723-740: Windows lstat pre-caching optimization looks correct.
The approach of pre-caching lstat metadata from directory entry on Windows is appropriate. Silently ignoring win32_xstat failures is acceptable since DirEntry.stat() will fall back to computing on demand when the cell is empty. This aligns with CPython's optimization strategy for Windows scandir.
742-754: DirEntry construction properly uses pre-cached lstat.
The pathval extraction moved earlier to share with the pre-caching logic, and the lstat field correctly uses the pre-cached OnceCell. The stat field remains separately cached since it may differ when following symlinks.
994-1001: Signature change correctly aligns with CPython's os.lstat() specification.
Python's os.lstat() accepts only path-like objects as the primary argument—it does not support file descriptors as the path. For file descriptor access, Python provides os.fstat(fd). The previous OsPathOrFd<'_> parameter was overly permissive and inconsistent with CPython's API. This change correctly restricts lstat() to paths only, matching the Python specification.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment @coderabbitai help to get the list of available commands and usage tips.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Dec 9, 2025
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|