Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gracefully handle PATH entires we don't have access to #115

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion zigup.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {},
}
Expand All @@ -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 => {},
}
Expand All @@ -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();
Expand All @@ -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();
Expand Down
Loading