rust-lang / rust-lang/rust

Tracking Issue for fs::rename_noreplace

Open
#161,427 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-filesystem A-io C-tracking-issue S-tracking-unimplemented T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Feature gate: #![feature(rename_noreplace)]

This is a tracking issue for std::fs::rename_noreplace.
It works similarly to std::fs::rename except that an existing destination is never overwritten, so the call fails with ErrorKind::AlreadyExists.

Should use appropriate OS primitives for platforms that have them, and use link/unlink approach as fallback on platforms that don't support it.
Platforms that have neither a rename-without-replace syscall nor hardlinks will return ErrorKind::Unsupported, unless alternative approach exists on those platforms.

Docs must be clear that this prevents TOCTOU races, but makes no atomicity or crash-safety guarantee.

Public API
// std::fs

pub fn rename_noreplace<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()>
Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

  • ACP: rust-lang/libs-team#131
  • Implementation #162027:
  • Final comment period (FCP)^1
  • Stabilization PR
Unresolved Questions
  • Directories on the fallback path: linkat will fail with EPERM, so they can't be moved there at all. The ACP suggests plain rename, so destination "must either not exist or must be an empty directory", so an empty destination directory would still be removed, or am I missing anything? Is that acceptable, or should directories error in such case?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with std::fs::rename_noreplace and implementation PR #162027, then review the platform checklist and the unresolved question about directories on the link/unlink fallback. Done requires the listed platform behavior, appropriate Unsupported handling, clear race-safety documentation, and eventual stabilization work.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.