Title: host_env: os.replace for Windows by joshuamegnauth54 · Pull Request #8212 · RustPython/RustPython · GitHub
Open Graph Title: host_env: os.replace for Windows by joshuamegnauth54 · Pull Request #8212 · RustPython/RustPython
X Title: host_env: os.replace for Windows by joshuamegnauth54 · Pull Request #8212 · RustPython/RustPython
Description: rename and replace are the same for Unixes but different for Windows in Python. POSIX's rename atomically replaces its target; there is no replace in POSIX. renameat2 with RENAME_NOREPLACE atomically checks if a file exists and renames if it doesn't, but Python's rename and replace predate renameat2. For Windows, rename acts like the RENAME_NOREPLACE flag while replace functions like rename. I implemented both using the Windows API. Both implementations follow CPython's code by using MoveFileExW. There are modern Windows APIs that may be worth using in the future. Rust's standard library prefers the modern APIs but falls back to MoveFileExW for deprecated Windows versions. Closes #xxxx This PR follows our AI policy Summary Implement os.replace for Windows. Summary by CodeRabbit New Features Added broader cross-platform support for directory-aware file operations, including rename, replace, and directory creation on Unix-like, WASI, and Windows environments. Improved handling of source and destination directory references for rename-style operations. Bug Fixes Fixed platform differences so file and directory operations behave more consistently across supported operating systems. Updated directory creation and rename-related parameter handling for better compatibility.
Open Graph Description: rename and replace are the same for Unixes but different for Windows in Python. POSIX's rename atomically replaces its target; there is no replace in POSIX. renameat2 with RENAME_NOREPLACE atom...
X Description: rename and replace are the same for Unixes but different for Windows in Python. POSIX's rename atomically replaces its target; there is no replace in POSIX. renameat2 with RENAME_NOREPLACE ...
Opengraph URL: https://github.com/RustPython/RustPython/pull/8212
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:85b2370e-80f0-b0b1-ba0a-4796fc696a32 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B04E:21233A:BD21CF:F691D8:6A601057 |
| html-safe-nonce | d619518028bd04ae3f7de0fe8f31c5c2d78fc5f6cc750e2591cf9079329c9347 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDRFOjIxMjMzQTpCRDIxQ0Y6RjY5MUQ4OjZBNjAxMDU3IiwidmlzaXRvcl9pZCI6IjU1Mjc3OTM5MDcyNjk2MzYxODQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 787fad91c05a29167bfb869ecaf0e9f293b82e14f9eaee9c179e8ef4666e75d5 |
| hovercard-subject-tag | pull_request:3995480142 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/8212/files |
| twitter:image | https://avatars.githubusercontent.com/u/48846352?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/48846352?s=400&v=4 |
| og:image:alt | rename and replace are the same for Unixes but different for Windows in Python. POSIX's rename atomically replaces its target; there is no replace in POSIX. renameat2 with RENAME_NOREPLACE atom... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 48cb2ed2304f8ae5a4a05d6327faf70466c4c0d9dcbf7b9df76251ca9c669a90 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cb0f10a384099e0765239a7cc220992cae52bdba |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width