From 85f2f53181d6f65226e6bc869129a58bbde7d785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hendrik=20Niel=C3=A4nder?= Date: Tue, 23 Jul 2024 17:47:03 +0200 Subject: [PATCH 1/3] chore: add zvm config file --- build.zig | 2 +- src/config.zig | 1 + src/install.zig | 5 ++--- src/versions.zig | 6 ++---- 4 files changed, 6 insertions(+), 8 deletions(-) create mode 100644 src/config.zig diff --git a/build.zig b/build.zig index 852dbc5..2016176 100644 --- a/build.zig +++ b/build.zig @@ -6,7 +6,7 @@ const CrossTargetInfo = struct { name: []const u8, }; // Semantic version of your application -const version = std.SemanticVersion{ .major = 0, .minor = 4, .patch = 3 }; +const version = std.SemanticVersion{ .major = 0, .minor = 4, .patch = 4 }; const min_zig_string = "0.13.0"; diff --git a/src/config.zig b/src/config.zig new file mode 100644 index 0000000..c819b9e --- /dev/null +++ b/src/config.zig @@ -0,0 +1 @@ +pub const download_manifest_url: []const u8 = "https://ziglang.org/download/index.json"; diff --git a/src/install.zig b/src/install.zig index 117084a..95e7ccb 100644 --- a/src/install.zig +++ b/src/install.zig @@ -1,5 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); +const config = @import("config.zig"); const hash = @import("hash.zig"); const download = @import("download.zig"); const architecture = @import("architecture.zig"); @@ -28,10 +29,8 @@ const Error = error{ ContentMissing, }; -const url = "https://ziglang.org/download/index.json"; - fn fetch_version_data(allocator: Allocator, requested_version: []const u8, sub_key: []const u8) !?Version { - const uri = std.Uri.parse(url) catch unreachable; + const uri = std.Uri.parse(config.download_manifest_url) catch unreachable; var client = std.http.Client{ .allocator = allocator }; defer client.deinit(); diff --git a/src/versions.zig b/src/versions.zig index f180f2a..5e27cac 100644 --- a/src/versions.zig +++ b/src/versions.zig @@ -1,9 +1,7 @@ const std = @import("std"); +const config = @import("config.zig"); -// TODO: The URL should be stored in a separate config file. -const url = "https://ziglang.org/download/index.json"; - -const uri = std.Uri.parse(url) catch unreachable; +const uri = std.Uri.parse(config.download_manifest_url) catch unreachable; pub const VersionList = struct { const List = std.ArrayList([]const u8); From f9b7e6cc902ae7362963036141ff3a32a320e861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hendrik=20Niel=C3=A4nder?= Date: Tue, 23 Jul 2024 21:42:48 +0200 Subject: [PATCH 2/3] fix: extract function --- src/extract.zig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/extract.zig b/src/extract.zig index 13e6eb2..66c34e5 100644 --- a/src/extract.zig +++ b/src/extract.zig @@ -15,22 +15,22 @@ pub fn extract_zip_dir(out_dir: std.fs.Dir, file: std.fs.File) !void { const allocator = arena.allocator(); const tmp_path = try tools.get_zvm_path_segment(allocator, "tmpdir"); - defer std.fs.delete_dir_absolute(tmp_path) catch unreachable; + defer std.fs.deleteDirAbsolute(tmp_path) catch unreachable; - try std.fs.make_dir_absolute(tmp_path); - var tmp_dir = try std.fs.open_dir_absolute(tmp_path, .{ .iterate = true }); + try std.fs.makeDirAbsolute(tmp_path); + var tmp_dir = try std.fs.openDirAbsolute(tmp_path, .{ .iterate = true }); try std.zip.extract(tmp_dir, file.seekable_stream(), .{}); var iterate = tmp_dir.iterate(); var sub_dir = blk: { const entry = try iterate.next() orelse return error.NotFound; - break :blk try tmp_dir.open_dir(entry.name, .{ .iterate = true }); + break :blk try tmp_dir.openDir(entry.name, .{ .iterate = true }); }; defer sub_dir.close(); - const sub_path = try sub_dir.realpath_alloc(allocator, ""); - defer std.fs.delete_dir_absolute(sub_path) catch unreachable; + 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| { From 09a492202e66559d5646451236b798cbc9982fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hendrik=20Niel=C3=A4nder?= Date: Tue, 23 Jul 2024 21:45:37 +0200 Subject: [PATCH 3/3] fix: extract function --- src/extract.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extract.zig b/src/extract.zig index 66c34e5..db5b517 100644 --- a/src/extract.zig +++ b/src/extract.zig @@ -20,7 +20,7 @@ pub fn extract_zip_dir(out_dir: std.fs.Dir, file: std.fs.File) !void { try std.fs.makeDirAbsolute(tmp_path); var tmp_dir = try std.fs.openDirAbsolute(tmp_path, .{ .iterate = true }); - try std.zip.extract(tmp_dir, file.seekable_stream(), .{}); + try std.zip.extract(tmp_dir, file.seekableStream(), .{}); var iterate = tmp_dir.iterate(); var sub_dir = blk: {