Skip to content

Commit 1b5bbbf

Browse files
committed
auto merge of #13865 : alexcrichton/rust/issue-13861, r=brson
Previously, windows was using the CREATE_NEW flag which fails if the file previously existed, which differed from the unix semantics. This alters the opening to use the OPEN_ALWAYS flag to mirror the unix semantics. Closes #13861
2 parents b0977b1 + 8375a22 commit 1b5bbbf

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/libnative/io/file_win32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ pub fn open(path: &CString, fm: io::FileMode, fa: io::FileAccess)
274274
(io::Truncate, io::Read) => libc::TRUNCATE_EXISTING,
275275
(io::Truncate, _) => libc::CREATE_ALWAYS,
276276
(io::Open, io::Read) => libc::OPEN_EXISTING,
277-
(io::Open, _) => libc::CREATE_NEW,
277+
(io::Open, _) => libc::OPEN_ALWAYS,
278278
(io::Append, io::Read) => {
279279
dwDesiredAccess |= libc::FILE_APPEND_DATA;
280280
libc::OPEN_EXISTING

src/libstd/io/fs.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,11 +1255,31 @@ mod test {
12551255
match File::open_mode(&tmpdir.join("a"), io::Open, io::Read) {
12561256
Ok(..) => fail!(), Err(..) => {}
12571257
}
1258+
1259+
// Perform each one twice to make sure that it succeeds the second time
1260+
// (where the file exists)
1261+
check!(File::open_mode(&tmpdir.join("b"), io::Open, io::Write));
1262+
assert!(tmpdir.join("b").exists());
12581263
check!(File::open_mode(&tmpdir.join("b"), io::Open, io::Write));
1264+
12591265
check!(File::open_mode(&tmpdir.join("c"), io::Open, io::ReadWrite));
1266+
assert!(tmpdir.join("c").exists());
1267+
check!(File::open_mode(&tmpdir.join("c"), io::Open, io::ReadWrite));
1268+
1269+
check!(File::open_mode(&tmpdir.join("d"), io::Append, io::Write));
1270+
assert!(tmpdir.join("d").exists());
12601271
check!(File::open_mode(&tmpdir.join("d"), io::Append, io::Write));
1272+
1273+
check!(File::open_mode(&tmpdir.join("e"), io::Append, io::ReadWrite));
1274+
assert!(tmpdir.join("e").exists());
12611275
check!(File::open_mode(&tmpdir.join("e"), io::Append, io::ReadWrite));
1276+
12621277
check!(File::open_mode(&tmpdir.join("f"), io::Truncate, io::Write));
1278+
assert!(tmpdir.join("f").exists());
1279+
check!(File::open_mode(&tmpdir.join("f"), io::Truncate, io::Write));
1280+
1281+
check!(File::open_mode(&tmpdir.join("g"), io::Truncate, io::ReadWrite));
1282+
assert!(tmpdir.join("g").exists());
12631283
check!(File::open_mode(&tmpdir.join("g"), io::Truncate, io::ReadWrite));
12641284

12651285
check!(File::create(&tmpdir.join("h")).write("foo".as_bytes()));

0 commit comments

Comments
 (0)