Skip to content

Commit

Permalink
fix for windows platform
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhongjia committed Aug 19, 2024
1 parent 2f5061a commit 6045071
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
12 changes: 12 additions & 0 deletions src/install.zig
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ fn install_zig(version: []const u8) !void {

try util_extract.extract(extract_dir, new_file, if (builtin.os.tag == .windows) .zip else .tarxz, false);

// mv
const sub_path = try std.fs.path.join(arena_allocator, &.{
extract_path, try std.mem.concat(
arena_allocator,
u8,
&.{ "zig-", reverse_platform_str, "-", version },
),
});
defer std.fs.deleteTreeAbsolute(sub_path) catch unreachable;

try util_tool.copy_dir(sub_path, extract_path);

try alias.set_version(version, false);
}

Expand Down
22 changes: 7 additions & 15 deletions src/util/extract.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const std = @import("std");
const builtin = @import("builtin");
const data = @import("data.zig");
const tool = @import("tool.zig");

const xz = std.compress.xz;
const tar = std.tar;
Expand Down Expand Up @@ -41,26 +42,17 @@ fn extract_zip_dir(out_dir: std.fs.Dir, file: std.fs.File) !void {
const allocator = arena.allocator();
// for decompressing zig, we need to make a temp directory
const tmp_path = try data.get_zvm_path_segment(allocator, "tmpdir");
defer std.fs.deleteDirAbsolute(tmp_path) catch unreachable;
defer std.fs.deleteTreeAbsolute(tmp_path) catch unreachable;

try std.fs.makeDirAbsolute(tmp_path);
var tmp_dir = try std.fs.openDirAbsolute(tmp_path, .{ .iterate = true });
defer tmp_dir.close();

// extract zig
// extract zip
try std.zip.extract(tmp_dir, file.seekableStream(), .{});

var iterate = tmp_dir.iterate();
var sub_dir = blk: {
const entry = try iterate.next() orelse return error.NotFound;
break :blk try tmp_dir.openDir(entry.name, .{ .iterate = true });
};
defer sub_dir.close();
const out_path = try out_dir.realpathAlloc(allocator, "");
defer allocator.free(out_path);

const sub_path = try sub_dir.realpathAlloc(allocator, "");
defer std.fs.deleteDirAbsolute(sub_path) catch unreachable;

var sub_iterate = sub_dir.iterate();
while (try sub_iterate.next()) |entry| {
try std.fs.rename(sub_dir, entry.name, out_dir, entry.name);
}
try tool.copy_dir(tmp_path, out_path);
}

0 comments on commit 6045071

Please sign in to comment.