From 33226c20c41e3fe2de3330b6692c90bc4818b119 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Tue, 15 Nov 2022 13:55:07 +0200 Subject: Don't download the archive to a file --- src/install.zig | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'src/install.zig') diff --git a/src/install.zig b/src/install.zig index 47b804c..5eb5a29 100644 --- a/src/install.zig +++ b/src/install.zig @@ -51,26 +51,20 @@ 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 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; } - std.log.info("Downloading to /tmp/{s}...", .{filename}); - try zup.http.downloadToFile(allocator, &tmpfile, installation.url.?); + if (response.body == null) { + std.log.err("HTTP Error, no body received", .{}); + return error.HttpError; + } std.log.info("Extracting...", .{}); var archive = try ArchiveRead.init(); @@ -78,7 +72,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(response.body.?); while (try archive.nextHeader()) |entry_c| { var entry = entry_c; -- cgit v1.2.3