fix openWriteNoClobber and add test
This commit is contained in:
parent
de18ece294
commit
7e54954052
@ -29,6 +29,17 @@ test "write a file, read it, then delete it" {
|
||||
try st.print("end");
|
||||
try buf_stream.flush();
|
||||
}
|
||||
|
||||
{
|
||||
// make sure openWriteNoClobber doesn't harm the file
|
||||
if (os.File.openWriteNoClobber(tmp_file_name, os.File.default_mode)) |file| {
|
||||
unreachable;
|
||||
}
|
||||
else |err| {
|
||||
std.debug.assert(err == os.File.OpenError.PathAlreadyExists);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
var file = try os.File.openRead(tmp_file_name);
|
||||
defer file.close();
|
||||
|
@ -105,7 +105,7 @@ pub const File = struct {
|
||||
pub fn openWriteNoClobber(path: []const u8, file_mode: Mode) OpenError!File {
|
||||
if (is_posix) {
|
||||
const path_c = try os.toPosixPath(path);
|
||||
return openWriteNoClobberC(path_c, file_mode);
|
||||
return openWriteNoClobberC(&path_c, file_mode);
|
||||
} else if (is_windows) {
|
||||
const path_w = try windows_util.sliceToPrefixedFileW(path);
|
||||
return openWriteNoClobberW(&path_w, file_mode);
|
||||
|
Loading…
x
Reference in New Issue
Block a user