Skip to content

Creating a file with a single colon in its name strips the part after the colon from the file name and produces an empty file (on Windows) #134671

Open
@FeldrinH

Description

@FeldrinH

I tried this code:

let mut f = File::create("before:after").unwrap();
f.write("test".as_bytes()).unwrap();
f.sync_all().unwrap();

I expected to see this happen:
The file creation produces an error, because file paths cannot contain colons on Windows.

Instead, this happened:
There were no errors. Instead, an empty file named before was created.

Note in particular:

  • The file was named before, despite the requested name being before:after.
  • The file was empty, despite the fact that the code succesfully wrote some text to it and synchronized the writes to disk.

Other observations:
When the file name contains multiple colons then the file creation does produce an error, as expected.

Meta

rustc --version --verbose:

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-pc-windows-msvc
release: 1.83.0
LLVM version: 19.1.1

Tested on Windows 10 Home version 10.0.19045 Build 19045.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-filesystemArea: `std::fs`C-discussionCategory: Discussion or questions that doesn't represent real issues.O-windowsOperating system: WindowsT-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