diff options
| author | 2022-11-15 13:55:07 +0200 | |
|---|---|---|
| committer | 2022-11-15 13:55:07 +0200 | |
| commit | 33226c20c41e3fe2de3330b6692c90bc4818b119 (patch) | |
| tree | 4e66df2da513eb7270c1d0ebc23aef3e264099f8 /src/install.zig | |
| parent | Replace my zig-curl with zelda (diff) | |
| download | zup-33226c20c41e3fe2de3330b6692c90bc4818b119.tar.gz zup-33226c20c41e3fe2de3330b6692c90bc4818b119.tar.xz zup-33226c20c41e3fe2de3330b6692c90bc4818b119.zip | |
Don't download the archive to a file
Diffstat (limited to 'src/install.zig')
| -rw-r--r-- | src/install.zig | 32 |
1 files changed, 13 insertions, 19 deletions
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 | |||
| 51 | defer allocator.free(installation_dir); | 51 | defer allocator.free(installation_dir); |
| 52 | 52 | ||
| 53 | std.log.info("Installing {s}, version {}", .{ name, installation.version }); | 53 | std.log.info("Installing {s}, version {}", .{ name, installation.version }); |
| 54 | const filename = std.fs.path.basename(installation.url.?); | 54 | |
| 55 | 55 | std.log.info("Downloading from {s}...", .{installation.url.?}); | |
| 56 | // TODO: Platform-agnostic tempfile creation | 56 | var response = try zelda.get(allocator, installation.url.?); |
| 57 | var tmpname = try std.fmt.allocPrintZ(allocator, "/tmp/{s}", .{filename}); | 57 | defer response.deinit(); |
| 58 | defer allocator.free(tmpname); | 58 | |
| 59 | 59 | if (response.status_code.group() != .success) { | |
| 60 | var tmpdir = try std.fs.openDirAbsolute(std.fs.path.dirname(tmpname).?, .{}); | 60 | std.log.err("HTTP Error: {}", .{response.status_code}); |
| 61 | defer tmpdir.close(); | 61 | return error.HttpError; |
| 62 | |||
| 63 | var tmpfile = try tmpdir.createFile(filename, .{}); | ||
| 64 | defer { | ||
| 65 | tmpfile.close(); | ||
| 66 | std.log.info("Deleting /tmp/{s}...", .{filename}); | ||
| 67 | tmpdir.deleteFile(filename) catch |err| { | ||
| 68 | std.log.warn("Failed to delete /tmp/{s}: {}", .{ filename, err }); | ||
| 69 | }; | ||
| 70 | } | 62 | } |
| 71 | 63 | ||
| 72 | std.log.info("Downloading to /tmp/{s}...", .{filename}); | 64 | if (response.body == null) { |
| 73 | try zup.http.downloadToFile(allocator, &tmpfile, installation.url.?); | 65 | std.log.err("HTTP Error, no body received", .{}); |
| 66 | return error.HttpError; | ||
| 67 | } | ||
| 74 | 68 | ||
| 75 | std.log.info("Extracting...", .{}); | 69 | std.log.info("Extracting...", .{}); |
| 76 | var archive = try ArchiveRead.init(); | 70 | var archive = try ArchiveRead.init(); |
| @@ -78,7 +72,7 @@ pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: I | |||
| 78 | 72 | ||
| 79 | try archive.supportFilter(.all); | 73 | try archive.supportFilter(.all); |
| 80 | try archive.supportFormat(.all); | 74 | try archive.supportFormat(.all); |
| 81 | try archive.openFilename(tmpname, 10240); | 75 | try archive.openMemory(response.body.?); |
| 82 | 76 | ||
| 83 | while (try archive.nextHeader()) |entry_c| { | 77 | while (try archive.nextHeader()) |entry_c| { |
| 84 | var entry = entry_c; | 78 | var entry = entry_c; |