From a6dbcffe2ce03f9571da693852181a785942ec4b Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Sun, 2 Apr 2023 21:47:15 +0300 Subject: Actually use my zig-curl instead of zelda. I'll wait until zelda & zig get more stable and get more contributors. Also, zelda has been archived on April 1st, perhaps a joke, perhaps not. This reverts commit 081e79c3fa385c662a5a6b7faf717ec370b398c8. This reverts commit 33226c20c41e3fe2de3330b6692c90bc4818b119. This reverts commit 3b3baf375be63acfd293b1b47a5f49aab4b06a70. --- src/install.zig | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src/install.zig') diff --git a/src/install.zig b/src/install.zig index 5eb5a29..27db4bb 100644 --- a/src/install.zig +++ b/src/install.zig @@ -1,7 +1,7 @@ const libarchive = @import("libarchive"); +const curl = @import("curl"); const std = @import("std"); const xdg = @import("xdg"); -const zelda = @import("zelda"); const zup = @import("zup"); const Allocator = std.mem.Allocator; @@ -51,20 +51,26 @@ 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 }); - - std.log.info("Downloading from {s}...", .{installation.url.?}); - var response = try zelda.get(allocator, installation.url.?); - defer response.deinit(); - - if (response.status_code.group() != .success) { - std.log.err("HTTP Error: {}", .{response.status_code}); - return error.HttpError; + 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 }); + }; } - if (response.body == null) { - std.log.err("HTTP Error, no body received", .{}); - return error.HttpError; - } + std.log.info("Downloading to /tmp/{s}...", .{filename}); + try curl.easyDownloadToFile(&tmpfile, installation.url.?); std.log.info("Extracting...", .{}); var archive = try ArchiveRead.init(); @@ -72,7 +78,7 @@ pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: I try archive.supportFilter(.all); try archive.supportFormat(.all); - try archive.openMemory(response.body.?); + try archive.openFilename(tmpname, 10240); while (try archive.nextHeader()) |entry_c| { var entry = entry_c; -- cgit v1.2.3