Skip to content

Commit ca2067d

Browse files
committed
show symlinked compilers in zigup list
1 parent b78400e commit ca2067d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

zigup.zig

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,22 @@ fn listCompilers(allocator: Allocator) !void {
569569
{
570570
var it = install_dir.iterate();
571571
while (try it.next()) |entry| {
572-
if (entry.kind != .directory)
572+
var target = entry.name;
573+
var link_buffer: [std.fs.max_path_bytes]u8 = undefined;
574+
var real_buffer: [std.fs.max_path_bytes]u8 = undefined;
575+
if (entry.kind == .sym_link) {
576+
const link_path = install_dir.readLink(entry.name, &link_buffer) catch continue;
577+
const real_path = install_dir.realpath(link_path, &real_buffer) catch continue;
578+
const relative = try std.fs.path.relative(allocator, install_dir_string, real_path);
579+
defer allocator.free(relative);
580+
if (std.fs.path.isAbsolute(relative) or std.mem.startsWith(u8, relative, "..")) {
581+
continue;
582+
}
583+
install_dir.access(link_path, .{}) catch continue;
584+
target = link_path;
585+
} else if (entry.kind != .directory)
573586
continue;
574-
if (std.mem.endsWith(u8, entry.name, ".installing"))
587+
if (std.mem.endsWith(u8, target, ".installing"))
575588
continue;
576589
try stdout.print("{s}\n", .{entry.name});
577590
}

0 commit comments

Comments
 (0)