From 37773432f6354f3639e0ed8e0557426cd7273764 Mon Sep 17 00:00:00 2001 From: jinzhongjia Date: Sat, 27 Jul 2024 14:38:33 +0800 Subject: [PATCH] fix: use `std.fs.accessAbsolute` to replace `std.fs.openDirAbsolute` This can solve the problem of file descriptors not being freed --- src/alias.zig | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/alias.zig b/src/alias.zig index aeb84f2..fdc2d47 100644 --- a/src/alias.zig +++ b/src/alias.zig @@ -80,26 +80,26 @@ fn copy_dir(source_dir: []const u8, dest_dir: []const u8) !void { } } +/// detect the dir whether exist fn does_dir_exist(path: []const u8) bool { const result = blk: { - _ = std.fs.openDirAbsolute(path, .{}) catch |err| { - switch (err) { - error.FileNotFound => break :blk false, - else => break :blk true, - } + std.fs.accessAbsolute(path, .{}) catch |err| { + if (err == error.FileNotFound) + break :blk false; + break :blk true; }; break :blk true; }; return result; } +/// detect the dir whether exist fn does_file_exist(path: []const u8) bool { const result = blk: { - _ = std.fs.cwd().openFile(path, .{}) catch |err| { - switch (err) { - error.FileNotFound => break :blk false, - else => break :blk true, - } + std.fs.accessAbsolute(path, .{}) catch |err| { + if (err == error.FileNotFound) + break :blk false; + break :blk true; }; break :blk true; };