| author | |
| committer | |
| log | 7e549540527fec891bc67d5e657f82b7087530a3 |
| tree | c534e4f2b4fbbaae2fac3575e7755e61afb64424 |
| parent | de18ece29436290cae3608d2c942e7e0a69f1a44 |
2 files changed, 12 insertions(+), 1 deletions(-)
std/io_test.zig+11| ... | @@ -29,6 +29,17 @@ test "write a file, read it, then delete it" { | ... | @@ -29,6 +29,17 @@ test "write a file, read it, then delete it" { |
| 29 | try st.print("end"); | 29 | try st.print("end"); |
| 30 | try buf_stream.flush(); | 30 | try buf_stream.flush(); |
| 31 | } | 31 | } |
| 32 | |||
| 33 | { | ||
| 34 | // make sure openWriteNoClobber doesn't harm the file | ||
| 35 | if (os.File.openWriteNoClobber(tmp_file_name, os.File.default_mode)) |file| { | ||
| 36 | unreachable; | ||
| 37 | } | ||
| 38 | else |err| { | ||
| 39 | std.debug.assert(err == os.File.OpenError.PathAlreadyExists); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 32 | { | 43 | { |
| 33 | var file = try os.File.openRead(tmp_file_name); | 44 | var file = try os.File.openRead(tmp_file_name); |
| 34 | defer file.close(); | 45 | defer file.close(); |
std/os/file.zig+1-1| ... | @@ -105,7 +105,7 @@ pub const File = struct { | ... | @@ -105,7 +105,7 @@ pub const File = struct { |
| 105 | pub fn openWriteNoClobber(path: []const u8, file_mode: Mode) OpenError!File { | 105 | pub fn openWriteNoClobber(path: []const u8, file_mode: Mode) OpenError!File { |
| 106 | if (is_posix) { | 106 | if (is_posix) { |
| 107 | const path_c = try os.toPosixPath(path); | 107 | const path_c = try os.toPosixPath(path); |
| 108 | return openWriteNoClobberC(path_c, file_mode); | 108 | return openWriteNoClobberC(&path_c, file_mode); |
| 109 | } else if (is_windows) { | 109 | } else if (is_windows) { |
| 110 | const path_w = try windows_util.sliceToPrefixedFileW(path); | 110 | const path_w = try windows_util.sliceToPrefixedFileW(path); |
| 111 | return openWriteNoClobberW(&path_w, file_mode); | 111 | return openWriteNoClobberW(&path_w, file_mode); |