close handles while making temporary paths

This commit is contained in:
Luna 2020-06-02 16:11:30 -03:00
parent d6c92c0231
commit 0240b10a3c
1 changed files with 9 additions and 5 deletions

View File

@ -95,12 +95,16 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
}
// if we fail to access it, we assume it doesn't exist and return it.
_ = std.fs.cwd().openFile(nam, .{ .read = true, .write = false }) catch |err| {
if (err == error.FileNotFound) {
return nam;
}
var tmp_file: std.fs.File = std.fs.cwd().openFile(
nam,
.{ .read = true, .write = false },
) catch |err| blk: {
if (err == error.FileNotFound) return nam else continue;
};
// if we actually found someone, close the handle so that we don't
// get EMFILE later on.
tmp_file.close();
}
return error.TempGenFail;