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/install.zig | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'src/install.zig') diff --git a/src/install.zig b/src/install.zig index 2e3efab..a459aa6 100644 --- a/src/install.zig +++ b/src/install.zig @@ -1,12 +1,13 @@ const libarchive = @import("libarchive"); -const curl = @import("curl"); const std = @import("std"); const xdg = @import("xdg"); const zup = @import("root"); const Allocator = std.mem.Allocator; -const Config = zup.Config; const ArchiveRead = libarchive.Read; +const ArenaAllocator = std.heap.ArenaAllocator; +const Config = zup.Config; +const EasyHttp = zup.EasyHttp; const Installation = zup.Installation; const Installations = zup.Installations; @@ -51,26 +52,11 @@ pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: I defer allocator.free(installation_dir); std.log.info("Installing {s}, version {}", .{ name, installation.version }); - const filename = std.fs.path.basename(installation.url.?); - - // TODO: Platform-agnostic tempfile creation - var tmpname = try std.fmt.allocPrintZ(allocator, "/tmp/{s}", .{filename}); - defer allocator.free(tmpname); - - var tmpdir = try std.fs.openDirAbsolute(std.fs.path.dirname(tmpname).?, .{}); - defer tmpdir.close(); - - var tmpfile = try tmpdir.createFile(filename, .{}); - defer { - tmpfile.close(); - std.log.info("Deleting /tmp/{s}...", .{filename}); - tmpdir.deleteFile(filename) catch |err| { - std.log.warn("Failed to delete /tmp/{s}: {}", .{ filename, err }); - }; - } - std.log.info("Downloading to /tmp/{s}...", .{filename}); - try curl.easyDownloadToFile(&tmpfile, installation.url.?); + std.log.info("Downloading from {s}...", .{installation.url_str.?}); + + var data = try EasyHttp.get(allocator, installation.url.?); + defer allocator.free(data); std.log.info("Extracting...", .{}); var archive = try ArchiveRead.init(); @@ -78,7 +64,7 @@ pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: I try archive.supportFilter(.all); try archive.supportFormat(.all); - try archive.openFilename(tmpname, 10240); + try archive.openMemory(data); while (try archive.nextHeader()) |entry_c| { var entry = entry_c; -- cgit v1.2.3