From 6aabe158cb33cc63d39356136e1cdeaa5b6f07b4 Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Tue, 12 Mar 2024 12:38:13 -0600 Subject: [PATCH] gracefully handle PATH entires we don't have access to Fixes an issue reported by user tech189 in issue #104. --- zigup.zig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/zigup.zig b/zigup.zig index d759be1..c863182 100644 --- a/zigup.zig +++ b/zigup.zig @@ -729,6 +729,9 @@ fn verifyPathLink(allocator: Allocator, path_link: []const u8) !void { while (path_it.next()) |path| { switch (try compareDir(path_link_dir_id, path)) { .missing => continue, + // can't be the same directory because we were able to open and get + // the file id for path_link_dir_id + .access_denied => {}, .match => return, .mismatch => {}, } @@ -755,6 +758,9 @@ fn verifyPathLink(allocator: Allocator, path_link: []const u8) !void { while (path_it.next()) |path| { switch (try compareDir(path_link_dir_id, path)) { .missing => continue, + // can't be the same directory because we were able to open and get + // the file id for path_link_dir_id + .access_denied => {}, .match => return, .mismatch => {}, } @@ -768,9 +774,10 @@ fn verifyPathLink(allocator: Allocator, path_link: []const u8) !void { return error.AlreadyReported; } -fn compareDir(dir_id: FileId, other_dir: []const u8) !enum { missing, match, mismatch } { +fn compareDir(dir_id: FileId, other_dir: []const u8) !enum { missing, access_denied, match, mismatch } { var dir = std.fs.cwd().openDir(other_dir, .{}) catch |err| switch (err) { error.FileNotFound, error.NotDir, error.BadPathName => return .missing, + error.AccessDenied => return .access_denied, else => |e| return e, }; defer dir.close(); @@ -780,6 +787,7 @@ fn compareDir(dir_id: FileId, other_dir: []const u8) !enum { missing, match, mis fn enforceNoZig(path_link: []const u8, exe: []const u8) !void { var file = std.fs.cwd().openFile(exe, .{}) catch |err| switch (err) { error.FileNotFound, error.IsDir => return, + error.AccessDenied => return, // if there is a Zig it must not be accessible else => |e| return e, }; defer file.close();