close handles while making temporary paths
This commit is contained in:
parent
d6c92c0231
commit
0240b10a3c
1 changed files with 9 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue