host_env: renameat support for os.rename#8118
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
Changesos.rename dir_fd support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/host_env/src/os.rs`:
- Around line 271-288: The error path in the rename function at line 286 returns
io::Error::other(...) directly, but the function signature specifies a return
type of io::Result<()>, which is Result<(), io::Error>. To fix this type
mismatch, wrap the io::Error::other(...) call with Err() so the error is
properly wrapped in the Result type, making the return statement consistent with
the function's declared return type.
In `@crates/vm/src/stdlib/os.rs`:
- Around line 1953-1954: The rename and replace functions unconditionally
advertise dir_fd support via Some(true) even though it only works on Unix
platforms. Add a new const RENAME_DIR_FD near the other *_DIR_FD constants that
uses cfg!(unix) to conditionally return true only on Unix systems, then update
the SupportFunc::new calls for both the "rename" and "replace" entries to use
Some(RENAME_DIR_FD) instead of Some(true) to accurately represent
platform-specific capability.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 3982ccbf-2610-4482-8a10-527c4eb2b558
📒 Files selected for processing (2)
crates/host_env/src/os.rscrates/vm/src/stdlib/os.rs
Python's `os.rename` supports renaming a path relative to a directory descriptor - essentially, `renameat`. The syscall and its Rustix wrapper does all of the work, so this patch mainly updates the Python signature to forward to the implementation. As of this patch, `os.rename` is still incorrect for Windows because it always replaces the destination file. I added a small note for future contributors (or myself, since I might tackle it) as a reminder of what's broken.
3cc207d to
073fa98
Compare
Python's
os.renamesupports renaming a path relative to a directory descriptor - essentially,renameat. The syscall and its Rustix wrapper does all of the work, so this patch mainly updates the Python signature to forward to the implementation.As of this patch,
os.renameis still incorrect for Windows because it always replaces the destination file. I added a small note for future contributors (or myself, since I might tackle it) as a reminder of what's broken.Summary
os.rename. See os.rename.Summary by CodeRabbit
os.rename()andos.replace()to accept optionalsrc_dir_fdanddst_dir_fd, enabling more flexible file operations.renameandreplaceare marked as supporting directory file descriptor parameters where available.renameatsupport is unavailable.