Skip to content

Commit

Permalink
fix: use std.fs.accessAbsolute to replace std.fs.openDirAbsolute
Browse files Browse the repository at this point in the history
This can solve the problem of file descriptors not being freed
  • Loading branch information
jinzhongjia committed Jul 27, 2024
1 parent 452d94f commit 3777343
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/alias.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 3777343

Please sign in to comment.