Skip to content

Windows: File::create fails when file already exists (cannot call SetFileInformationByHandle) #4483

@RalfJung

Description

@RalfJung

When calling File::create and the file already exists, we hit an error on Windows targets:

  error: unsupported operation: can't call foreign function `SetFileInformationByHandle` on OS `windows`
    --> C:\Users\runneradmin\.rustup\toolchains\miri\lib\rustlib\src\rust\library\std\src\sys\pal\windows\api.rs:231:26
     |
  LL |             let result = c::SetFileInformationByHandle(handle, class, info, size);
     |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsupported operation occurred here
     |
     = help: this means the program tried to do something Miri does not support; it does not indicate a bug in the program
     = note: BACKTRACE:
     = note: inside `std::sys::pal::windows::api::set_file_information_by_handle::set_info` at C:\Users\runneradmin\.rustup\toolchains\miri\lib\rustlib\src\rust\library\std\src\sys\pal\windows\api.rs:231:26: 231:82
     = note: inside `std::sys::pal::windows::api::set_file_information_by_handle::<std::sys::pal::windows::c::windows_sys::FILE_ALLOCATION_INFO>` at C:\Users\runneradmin\.rustup\toolchains\miri\lib\rustlib\src\rust\library\std\src\sys\pal\windows\api.rs:236:14: 236:68
     = note: inside `std::sys::fs::windows::File::open_native` at C:\Users\runneradmin\.rustup\toolchains\miri\lib\rustlib\src\rust\library\std\src\sys\fs\windows.rs:333:17: 333:79
     = note: inside `std::sys::fs::windows::File::open` at C:\Users\runneradmin\.rustup\toolchains\miri\lib\rustlib\src\rust\library\std\src\sys\fs\windows.rs:305:9: 305:39
     = note: inside `std::fs::OpenOptions::_open` at C:\Users\runneradmin\.rustup\toolchains\miri\lib\rustlib\src\rust\library\std\src\fs.rs:1711:9: 1711:42
     = note: inside `std::fs::OpenOptions::open::<&std::path::Path>` at C:\Users\runneradmin\.rustup\toolchains\miri\lib\rustlib\src\rust\library\std\src\fs.rs:1707:9: 1707:34
     = note: inside `std::fs::File::create::<&std::path::PathBuf>` at C:\Users\runneradmin\.rustup\toolchains\miri\lib\rustlib\src\rust\library\std\src\fs.rs:521:9: 521:87
  note: inside closure
    --> tests/pass\shims\fs.rs:83:24
     |
  LL |         let mut file = File::create(&path).unwrap();
     |                        ^^^^^^^^^^^^^^^^^^^

Not sure why this has a different codepath, but this has to be this codepath.

Cc @CraftSpider -- any chance you could take a look at this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-filesArea: related to files, paths, sockets, file descriptors, or handlesA-windowsArea: affects only Windows targetsC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions