Skip to content

fs::Dir::rename: make absolute paths work on Windows - #166524

Open
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:dir-win-rename-absolute
Open

RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:dir-win-rename-absolute

Conversation

@RalfJung

@RalfJung RalfJung commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

View all comments

View all comments

To make Dir more consistent between Windows and Unix, it should work on absolute paths. Dir::open_file already had logic for that. This does something similar for Dir::rename. That would make life easier for Miri when renaming from/to arbitrary files, where source and/or target may or may not be relative to a Dir handle. (Eventually we may want to reorganize this so all operations support absolute paths, as part of a larger refactoring. I'm leaving that to future work. Miri only needs this for rename because for all other operations it is easy to fall back to a regular stable function in fs when no Dir handle is involved.)

Tracking issue: #120426

try-job: test-x86_64-msvc*

@rustbot rustbot added A-filesystem Area: `std::fs` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 24, 2026
@rustbot

rustbot commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

r? @clarfonthey

rustbot has assigned @clarfonthey.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 38 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, clarfonthey

@RalfJung

Copy link
Copy Markdown
Member Author

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 24, 2026
fs::Dir: make absolute paths work on Windows in more situations

try-job: test-x86_64-msvc*
@RalfJung
RalfJung force-pushed the dir-win-rename-absolute branch from 456e77a to f8fd835 Compare November 24, 2026 19:58
@RalfJung

Copy link
Copy Markdown
Member Author

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 24, 2026
fs::Dir: make absolute paths work on Windows in more situations

try-job: test-x86_64-msvc*
@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 24, 2026
@rust-bors

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@RalfJung
RalfJung force-pushed the dir-win-rename-absolute branch 2 times, most recently from 266408f to 79e4535 Compare November 25, 2026 07:28
@RalfJung
RalfJung marked this pull request as draft November 25, 2026 07:30
@RalfJung

Copy link
Copy Markdown
Member Author

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 25, 2026
fs::Dir: make absolute paths work on Windows in more situations

try-job: test-x86_64-msvc*
@RalfJung RalfJung changed the title fs::Dir: make absolute paths work on Windows in more situations fs::Dir::rename: make absolute paths work on Windows Nov 25, 2026
@rust-log-analyzer

This comment has been minimized.

@RalfJung

Copy link
Copy Markdown
Member Author

@ChrisDenton looks like the Nt methods do not like paths that start with C:\...? What is the best way to turn such a path into one that the Nt methods do like, so that one can rename a file relative to a Dir into a file at some absolute path?

@rust-bors

This comment was marked as outdated.

@RalfJung

Copy link
Copy Markdown
Member Author

The best I can come up with is to open a dir handle for the parent directory, and then use that as the basis for the to part of the rename.

@RalfJung
RalfJung force-pushed the dir-win-rename-absolute branch from 79e4535 to 5de9ebb Compare November 25, 2026 14:39
@RalfJung

Copy link
Copy Markdown
Member Author

@bors try

rust-bors Bot pushed a commit that referenced this pull request Nov 25, 2026
fs::Dir::rename: make absolute paths work on Windows

try-job: test-x86_64-msvc*
@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@RalfJung
RalfJung force-pushed the dir-win-rename-absolute branch from 5de9ebb to 48c8740 Compare November 25, 2026 17:07
@RalfJung

Copy link
Copy Markdown
Member Author

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 25, 2026
fs::Dir::rename: make absolute paths work on Windows

try-job: test-x86_64-msvc*
@rust-bors

rust-bors Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: a8522c3 (a8522c3783e4baa180fc84a4091d64260d10e940)
Base parent: bc9132d (bc9132daa5c0be572ebb81304f6039d947298e67)

@RalfJung
RalfJung marked this pull request as ready for review November 25, 2026 19:48
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 25, 2026
@RalfJung

Copy link
Copy Markdown
Member Author

@rustbot ready

@rust-bors

rust-bors Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #166754) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-filesystem Area: `std::fs` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants