Skip to content

create_dir_all can't create directories through a dangling symlink. #31594

Open
@pitdicker

Description

@pitdicker

Currently create_dir_all first does a stat on the file to see if it is a directory, and if not tries to create the parent dirs. This does not take into account that stat can fail if the path is a dangling symlink.
The classic mkdir -p just tries to create a directory and see why it fails. This spares a syscall and handles dangling symlinks transparently.

On Windows this method hit two problems:

  • When we have to recurse all the way op to the disk letter, create_dir_all fails.
    You can't mkdir c:\ or \\host\share. But we can just stop recursing in time.
  • Windows can't create a directory through a dangling symlink.
    We would have to read the symlink (and possibly resolve it if relative), and create the directory
    at the target location ourself.

Would it make sense to go trough this trouble?

I think it is best to only fix this for create_dir_all and to document the normal create_dir can not
create a directory trough a dangling symlink on Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-feature-acceptedCategory: A feature request that has been accepted pending implementation.T-libs-apiRelevant to the library API 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