From f81f97955ad30830cde97a1693a309c87ce2ae21 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Tue, 26 Sep 2023 02:02:54 +0300 Subject: Remove curl --- src/Installation.zig | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/Installation.zig') diff --git a/src/Installation.zig b/src/Installation.zig index 54b870c..8218f23 100644 --- a/src/Installation.zig +++ b/src/Installation.zig @@ -1,4 +1,3 @@ -const curl = @import("curl"); const std = @import("std"); const xdg = @import("xdg"); const zup = @import("root"); @@ -7,9 +6,11 @@ const Allocator = std.mem.Allocator; const ArenaAllocator = std.heap.ArenaAllocator; const Config = zup.Config; const ChildProcess = std.ChildProcess; +const EasyHttp = zup.EasyHttp; const JsonValue = std.json.Value; const SemanticVersion = std.SemanticVersion; const StringHashMap = std.StringHashMap; +const Uri = std.Uri; const Installation = @This(); @@ -18,11 +19,12 @@ pub const Installations = StringHashMap(Installation); allocator: Allocator, ver_str: []u8, version: SemanticVersion, -url: ?[:0]u8, +url_str: ?[]u8, +url: ?Uri, pub fn deinit(self: *Installation) void { self.allocator.free(self.ver_str); - if (self.url) |url| self.allocator.free(url); + if (self.url_str) |str| self.allocator.free(str); self.* = undefined; } @@ -118,6 +120,7 @@ pub fn getInstalledList(allocator: Allocator) !Installations { .allocator = allocator, .ver_str = res.stdout, .version = version, + .url_str = null, .url = null, }); } @@ -133,18 +136,21 @@ pub fn isInstalled(allocator: Allocator, name: []const u8) !bool { return true; } +const index_json_uri = Uri.parse("https://ziglang.org/download/index.json") catch unreachable; + pub fn getAvailableList(config: Config) !Installations { var arena = ArenaAllocator.init(config.allocator); defer arena.deinit(); const allocator = arena.allocator(); - const json_str = try curl.easyDownload(allocator, "https://ziglang.org/download/index.json"); + var data = try EasyHttp.get(allocator, index_json_uri); + defer allocator.free(data); const parsed = try std.json.parseFromSliceLeaky( JsonValue, allocator, - json_str, + data, .{}, ); @@ -203,8 +209,9 @@ fn parseInstallation(config: Config, name: []const u8, value: JsonValue) !?Insta if (url_src != .string) { return error.JsonSchema; } - var url = try allocator.dupeZ(u8, url_src.string); - errdefer allocator.free(url); + var url_str = try allocator.dupe(u8, url_src.string); + errdefer allocator.free(url_str); + const url = try Uri.parse(url_str); const version_src = if (map.get("version")) |ver| blk: { if (ver != .string) { @@ -223,6 +230,7 @@ fn parseInstallation(config: Config, name: []const u8, value: JsonValue) !?Insta .allocator = allocator, .ver_str = ver_str, .version = version, + .url_str = url_str, .url = url, }; } -- cgit v1.2.3