From 3cbc42a05e8562e986bdbaf389f6bef4c5541d92 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Mon, 3 Feb 2025 17:00:56 +0100 Subject: [PATCH] fix: `std.fs.accessAbsolute` with `.read_write` outputs stack trace https://github.com/ziglang/zig/issues/22733 --- src/lib/buzz_fs.zig | 4 ++-- tests/025-fs.buzz | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/buzz_fs.zig b/src/lib/buzz_fs.zig index 40d24471..7609fe06 100644 --- a/src/lib/buzz_fs.zig +++ b/src/lib/buzz_fs.zig @@ -343,11 +343,11 @@ pub export fn exists(ctx: *api.NativeCtx) callconv(.c) c_int { var accessed = true; if (std.fs.path.isAbsolute(filename_slice)) { - std.fs.accessAbsolute(filename_slice, .{ .mode = .read_write }) catch { + std.fs.accessAbsolute(filename_slice, .{ .mode = .read_only }) catch { accessed = false; }; } else { - std.fs.cwd().access(filename_slice, .{ .mode = .read_write }) catch { + std.fs.cwd().access(filename_slice, .{ .mode = .read_only }) catch { accessed = false; }; } diff --git a/tests/025-fs.buzz b/tests/025-fs.buzz index 91ee8916..069f3daf 100644 --- a/tests/025-fs.buzz +++ b/tests/025-fs.buzz @@ -32,6 +32,8 @@ test "ls" { foreach (el in fs\list("/doesnotexist") catch ["wentwrong"]) { std\assert(el == "wentwrong", message: "Trying to list a non existent directory raised an error"); } + + std\assert(fs\exists("README.md"), message: "fs\\exists"); } test "move" {