-
Notifications
You must be signed in to change notification settings - Fork 1.4k
nt is_dir,is_file,listmount,listvolume #6373
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
Conversation
WalkthroughThese changes introduce Windows-specific functionality: a new maximum environment variable constant, two volume enumeration functions for the nt module ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
ac19e43 to
2dab1f6
Compare
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.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Lib/test/test_os.pyis excluded by!Lib/**
📒 Files selected for processing (3)
crates/common/src/windows.rs(1 hunks)crates/vm/src/stdlib/nt.rs(1 hunks)crates/vm/src/stdlib/os.rs(5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto 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/common/src/windows.rscrates/vm/src/stdlib/nt.rscrates/vm/src/stdlib/os.rs
🧠 Learnings (1)
📚 Learning: 2025-06-28T16:31:03.991Z
Learnt from: arihant2math
Repo: RustPython/RustPython PR: 5790
File: build.rs:2-2
Timestamp: 2025-06-28T16:31:03.991Z
Learning: In Cargo build scripts (build.rs), the environment variable CARGO_CFG_TARGET_OS is guaranteed to exist and is automatically set by Cargo during the build process, making unwrap() safe to use when accessing this variable.
Applied to files:
crates/vm/src/stdlib/os.rs
🧬 Code graph analysis (1)
crates/vm/src/stdlib/nt.rs (1)
crates/vm/src/stdlib/os.rs (1)
errno_err(39-41)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Check Rust code with clippy
🔇 Additional comments (6)
crates/vm/src/stdlib/nt.rs (2)
685-717: LGTM! Volume enumeration implementation looks correct.The handle lifecycle is properly managed:
FindVolumeCloseis called on anyFindNextVolumeWfailure, covering both normal termination (ERROR_NO_MORE_FILES) and error conditions. The buffer size ofMAX_PATH + 1is appropriate for volume GUIDs.Minor observation:
from_utf16_lossysilently replaces invalid sequences. This is acceptable for volume names which should always be valid UTF-16.
719-764: LGTM! Mount path enumeration handles dynamic buffer sizing correctly.The retry loop for
ERROR_MORE_DATAwith buffer resizing follows the standard Windows pattern. The null-separated string parsing with double-null termination detection (lines 757-758) is correct.crates/common/src/windows.rs (1)
6-8: LGTM!The constant value 32767 correctly matches the Windows CRT
_MAX_ENVdefinition, and the doc comment clearly identifies the source.crates/vm/src/stdlib/os.rs (3)
431-443: LGTM! Windows environment variable length validation.The helper function correctly validates against
_MAX_ENVand provides a clear error message.
529-546: LGTM! Windows fallback foris_dirhandles race conditions.The fallback to cached
file_typewhen the file is removed between directory enumeration and theis_dircall is a sensible approach for Windows. This matches CPython's behavior of using directory entry metadata when the file no longer exists.
548-565: LGTM! Consistent pattern withis_dir.The
is_filerefactoring mirrors theis_dirimplementation with the same Windows-specific fallback to cachedfile_typeonNotFound.
| // For unsetenv, size is key + '=' (no value, just clearing) | ||
| #[cfg(windows)] | ||
| check_env_var_len(key.len() + 1, vm)?; |
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.
Potential off-by-one: missing null terminator in size calculation.
The comment states "size is key + '='" but Windows _MAX_ENV includes the null terminator. For unsetenv, Windows internally sets "KEY=\0", so the size should be key.len() + 2 (key + '=' + '\0'), not key.len() + 1.
// For unsetenv, size is key + '=' (no value, just clearing)
#[cfg(windows)]
- check_env_var_len(key.len() + 1, vm)?;
+ check_env_var_len(key.len() + 2, vm)?; // key + '=' + '\0'📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // For unsetenv, size is key + '=' (no value, just clearing) | |
| #[cfg(windows)] | |
| check_env_var_len(key.len() + 1, vm)?; | |
| // For unsetenv, size is key + '=' (no value, just clearing) | |
| #[cfg(windows)] | |
| check_env_var_len(key.len() + 2, vm)?; // key + '=' + '\0' |
🤖 Prompt for AI Agents
In crates/vm/src/stdlib/os.rs around lines 483 to 485, the size computed for
unsetenv on Windows omits the null terminator; change the Windows branch to pass
key.len() + 2 (key + '=' + '\0') into check_env_var_len instead of key.len() + 1
so the length accounts for the terminating NUL when validating against _MAX_ENV.
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.