nt is_dir,is_file,listmount,listvolume by youknowone · Pull Request #6373 · RustPython/RustPython
Walkthrough
These changes introduce Windows-specific functionality: a new maximum environment variable constant, two volume enumeration functions for the nt module (listvolumes and listmounts), environment variable length validation in the os module, and refactored DirEntry metadata handling with Windows fallback behavior.
Changes
| Cohort / File(s) | Summary |
|---|---|
Windows Constants crates/common/src/windows.rs |
Added public constant _MAX_ENV with value 32767 representing the Windows CRT maximum environment variable size. |
nt Module Volume Functions crates/vm/src/stdlib/nt.rs |
Introduced listvolumes() to enumerate volume names using Windows API (FindFirstVolumeW/FindNextVolumeW), and listmounts(volume) to resolve mount paths for a volume using GetVolumePathNamesForVolumeNameW with dynamic buffer sizing. Both return Python lists and handle Windows I/O errors. |
os Module Enhancements crates/vm/src/stdlib/os.rs |
Added Windows-specific environment variable length validation in putenv() and unsetenv() against _MAX_ENV. Refactored DirEntry.is_dir() and is_file() to directly use metadata queries with Windows-specific NotFound fallback using cached file_type data. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~22 minutes
- crates/vm/src/stdlib/nt.rs: Windows API integration and buffer handling logic in
listmounts()requires careful verification of error paths and null-separated string parsing. - crates/vm/src/stdlib/os.rs: Platform-specific fallback behavior in
DirEntrymethods needs validation that WindowsNotFounderrors are handled correctly and cached data is reliable; env validation boundary conditions should be verified. - Cross-file consistency: Verify that
_MAX_ENVconstant usage in os.rs aligns with Windows CRT specifications.
Possibly related PRs
- Windows execv, spawnv, wait #6350: Modifies the Windows nt module and environment-related handling, overlapping with volume/environment changes in this PR.
- fix scandir/lstat for windows #6357: Refactors
DirEntrymetadata handling and adds cached lstat data, directly overlapping with theDirEntry.is_dir()andis_file()refactoring in this PR.
Poem
🐰 Hopping through Windows, volumes we find,
Mount paths and metadata, cleverly aligned,
Environment checks, no overflow today,
DirEntry now falters the NotFound way! ✨
Pre-merge checks and finishing touches
❌ Failed checks (1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Title check | ❓ Inconclusive | The title references specific function names (is_dir, is_file, listmount, listvolume) that are implemented in the changeset, but uses unclear abbreviations and lacks context about what was actually changed. | Rewrite the title to be more descriptive, such as 'Add Windows volume/mount listing and improve directory metadata handling' or 'Implement nt.listvolumes/listmounts and fix is_dir/is_file on Windows'. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✨ Finishing touches
- 📝 Generate docstrings
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
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.
Comment @coderabbitai help to get the list of available commands and usage tips.