Skip to content

Commit

Permalink
gracefully handle PATH entires we don't have access to
Browse files Browse the repository at this point in the history
Fixes an issue reported by user tech189 in issue #104.
  • Loading branch information
marler8997 committed Mar 12, 2024
1 parent 0ac4097 commit 0cfeb06
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 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 => continue,
.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 => continue,
.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 Down

0 comments on commit 0cfeb06

Please sign in to comment.