Skip to content

Tracking Issue for fs::rename_noreplace #161427

Description

@valentynkit

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.)

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?

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-filesystemArea: `std::fs`A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions