Skip to content

Tracking Issue for file_create_new #105135

Closed

Description

@yjhn

Feature gate: #![feature(file_create_new)]

This is a tracking issue for std::fs::File::create_new(path) function. It is related to RFC 1252, but isn't part of the RFC.

Public API

// std::fs

impl File 
    pub fn create_new<P: AsRef<Path>>(path: P) -> io::Result<File>
}

Steps / History

Unresolved Questions

  • None yet.

Footnotes

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

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    T-libs-api[DEPRECATED; DO NOT USE]
    on Dec 1, 2022
  2. Noratrieb commented on Dec 1, 2022

    @Noratrieb
    Member

    This was implemented in #98801.

  3. added a commit that references this issue on Dec 2, 2022
  4. joshtriplett commented on Oct 27, 2023

    @joshtriplett
    Member

    This has been implemented for a while, and seems to work as advertised.

    Shall we stabilize it?

    @rfcbot merge

  5. rfcbot commented on Oct 27, 2023

    @rfcbot

    Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

    No concerns currently listed.

    Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

    See this document for info about what commands tagged team members can give me.

  6. added
    proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
    disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.
    on Oct 27, 2023
  7. BurntSushi commented on Oct 28, 2023

    @BurntSushi
    Member

    Is this a common enough routine to need to justify its own constructor on File? Needing to use OpenOptions for a case like this seems okay to me?

  8. added
    final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
    and removed
    proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
    on Nov 7, 2023
  9. rfcbot commented on Nov 7, 2023

    @rfcbot

    🔔 This is now entering its final comment period, as per the review above. 🔔

  10. mr-bit commented on Nov 10, 2023

    @mr-bit

    File::create returns a file in write-only mode but File::create_new returns a file in read-write mode. What is the reason for this difference?

  11. added
    to-announceAnnounce this issue on triage meeting
    and removed
    final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
    on Nov 17, 2023
  12. rfcbot commented on Nov 17, 2023

    @rfcbot

    The final comment period, with a disposition to merge, as per the review above, is now complete.

    As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

    This will be merged soon.

  13. joshtriplett commented on Nov 21, 2023

    @joshtriplett
    Member

    Is this a common enough routine to need to justify its own constructor on File? Needing to use OpenOptions for a case like this seems okay to me?

    The use case for create_new seems at least as common as create, in filesystem code that I've observed. create is useful for "the user told me to write to a specific filename, which may or may not exist" (e.g. shell redirection or a -o option). create_new is used when writing out a file expected to not exist, where using create might introduce a bug and potentially a security vulnerability. Having only create and not create_new seems likely to steer people towards create even if it's not what they should be using, which would make such bugs more likely. Having both makes it obvious that the user needs to select the appropriate one for their use case.

  14. BurntSushi commented on Nov 21, 2023

    @BurntSushi
    Member

    @joshtriplett I buy it! Thanks for explaining. :)

  15. joshtriplett commented on Nov 21, 2023

    @joshtriplett
    Member

    File::create returns a file in write-only mode but File::create_new returns a file in read-write mode. What is the reason for this difference?

    File::create is useful for "the user asked me to write to this specific filename, which may or may not exist", such as for a user-specified output file. In that scenario, if it does exist, it might be write-only (e.g. a magic device file). For instance, consider echo 1 | sudo tee /proc/sys/vm/drop_caches on Linux: that file can be written, but not read, and attempting to open it read-write will return "permission denied".

    That doesn't apply to File::create_new: it always makes a new file, which means it will always be an ordinary file, so there's no reason it needs to be write-only. And given that it doesn't need to be write-only, read-write is the more convenient choice.

  16. m-ou-se commented on Nov 23, 2023

    @m-ou-se
    Member

    Thanks for those very clear explanations, @joshtriplett!

  17. m-ou-se commented on Dec 5, 2023

    @m-ou-se
    Member

    (This is now just waiting on a stabilization PR.)

  18. added a commit that references this issue on Dec 23, 2023
    b136919
  19. added a commit that references this issue on Dec 23, 2023
    9b21d24
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

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions