From 7be7496ec859c04cfbaf010bd420bcb57cb6cda2 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 30 Aug 2022 01:07:46 +0200 Subject: [PATCH 1/2] only conditionally ask for global configuration in setup wizard --- src/setup.zig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/setup.zig b/src/setup.zig index a25de9b..2abf634 100644 --- a/src/setup.zig +++ b/src/setup.zig @@ -121,18 +121,18 @@ pub fn wizard(allocator: std.mem.Allocator) !void { defer if (local_path) |d| allocator.free(d); defer if (global_path) |d| allocator.free(d); + const can_access_global = blk: { + std.fs.accessAbsolute(global_path orelse break :blk false, .{}) catch break :blk false; + break :blk true; + }; + if (global_path == null and local_path == null) { write("Could not open a global or local config directory.\n"); return; } var config_path: []const u8 = undefined; - if (try askBool("Should this configuration be system-wide?")) { - if (global_path) |p| { - config_path = p; - } else { - write("Could not find a global config directory.\n"); - return; - } + if (can_access_global and global_path != null and try askBool("Should this configuration be system-wide?")) { + config_path = global_path.?; } else { if (local_path) |p| { config_path = p; From d30cdabfe525017631a087024729862dc15cfdd5 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 30 Aug 2022 19:01:12 +0200 Subject: [PATCH 2/2] remove unnecessary check in setup wizard --- src/setup.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup.zig b/src/setup.zig index 2abf634..8d124f8 100644 --- a/src/setup.zig +++ b/src/setup.zig @@ -131,7 +131,7 @@ pub fn wizard(allocator: std.mem.Allocator) !void { return; } var config_path: []const u8 = undefined; - if (can_access_global and global_path != null and try askBool("Should this configuration be system-wide?")) { + if (can_access_global and try askBool("Should this configuration be system-wide?")) { config_path = global_path.?; } else { if (local_path) |p| {