File::create doesn't throw errors on non-existing paths
Created by: xTibor
Found this bug while I was experimenting with my custom scheme drivers.
Reproduction:
use std::fs::File;
fn main() {
match File::create("/tmp/non_existing_dir/something.txt") {
Ok(_) => println!("Success"),
Err(err) => println!("Fail: {:?}", err),
}
}
Expected behavior:
Stdout: Fail: Error { repr: Os { code: 2, message: "No such file or directory" } }
The system should throw an error when it couldn't find the specified path. The snippet above works this way on Linux.
Actual behavior:
First case: Nothing at /tmp/something.txt:
Stdout: Success
The system creates a file at /tmp/something.txt
, in the parent of the non-existing directory. Clearly not where I specified to do so.
Second case: /tmp/something.txt already exists:
Stdout: Fail: Error { repr: Os { code: 17, message: "File exists" } }
It tries to recreate the file at /tmp/something.txt
without success. It shouldn't even touch this file at all.
Build information:
- rustc 1.17.0-nightly (4be034e62 2017-02-27)
- Latest HEAD (https://github.com/redox-os/redox/commit/a227bb50c939b9d47ed8da6764694d9fa1e54eca)