diff options
| author | 2023-09-26 02:02:54 +0300 | |
|---|---|---|
| committer | 2023-09-26 02:19:34 +0300 | |
| commit | f81f97955ad30830cde97a1693a309c87ce2ae21 (patch) | |
| tree | 607a981809770e3af4e77ec86ad3495c11d984e1 /src/install.zig | |
| parent | Update README (diff) | |
| download | zup-f81f97955ad30830cde97a1693a309c87ce2ae21.tar.gz zup-f81f97955ad30830cde97a1693a309c87ce2ae21.tar.xz zup-f81f97955ad30830cde97a1693a309c87ce2ae21.zip | |
Remove curl
Diffstat (limited to 'src/install.zig')
| -rw-r--r-- | src/install.zig | 30 |
1 files changed, 8 insertions, 22 deletions
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 @@ | |||
| 1 | const libarchive = @import("libarchive"); | 1 | const libarchive = @import("libarchive"); |
| 2 | const curl = @import("curl"); | ||
| 3 | const std = @import("std"); | 2 | const std = @import("std"); |
| 4 | const xdg = @import("xdg"); | 3 | const xdg = @import("xdg"); |
| 5 | const zup = @import("root"); | 4 | const zup = @import("root"); |
| 6 | 5 | ||
| 7 | const Allocator = std.mem.Allocator; | 6 | const Allocator = std.mem.Allocator; |
| 8 | const Config = zup.Config; | ||
| 9 | const ArchiveRead = libarchive.Read; | 7 | const ArchiveRead = libarchive.Read; |
| 8 | const ArenaAllocator = std.heap.ArenaAllocator; | ||
| 9 | const Config = zup.Config; | ||
| 10 | const EasyHttp = zup.EasyHttp; | ||
| 10 | const Installation = zup.Installation; | 11 | const Installation = zup.Installation; |
| 11 | const Installations = zup.Installations; | 12 | const Installations = zup.Installations; |
| 12 | 13 | ||
| @@ -51,26 +52,11 @@ pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: I | |||
| 51 | defer allocator.free(installation_dir); | 52 | defer allocator.free(installation_dir); |
| 52 | 53 | ||
| 53 | std.log.info("Installing {s}, version {}", .{ name, installation.version }); | 54 | std.log.info("Installing {s}, version {}", .{ name, installation.version }); |
| 54 | const filename = std.fs.path.basename(installation.url.?); | ||
| 55 | |||
| 56 | // TODO: Platform-agnostic tempfile creation | ||
| 57 | var tmpname = try std.fmt.allocPrintZ(allocator, "/tmp/{s}", .{filename}); | ||
| 58 | defer allocator.free(tmpname); | ||
| 59 | |||
| 60 | var tmpdir = try std.fs.openDirAbsolute(std.fs.path.dirname(tmpname).?, .{}); | ||
| 61 | defer tmpdir.close(); | ||
| 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 | } | ||
| 71 | 55 | ||
| 72 | std.log.info("Downloading to /tmp/{s}...", .{filename}); | 56 | std.log.info("Downloading from {s}...", .{installation.url_str.?}); |
| 73 | try curl.easyDownloadToFile(&tmpfile, installation.url.?); | 57 | |
| 58 | var data = try EasyHttp.get(allocator, installation.url.?); | ||
| 59 | defer allocator.free(data); | ||
| 74 | 60 | ||
| 75 | std.log.info("Extracting...", .{}); | 61 | std.log.info("Extracting...", .{}); |
| 76 | var archive = try ArchiveRead.init(); | 62 | var archive = try ArchiveRead.init(); |
| @@ -78,7 +64,7 @@ pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: I | |||
| 78 | 64 | ||
| 79 | try archive.supportFilter(.all); | 65 | try archive.supportFilter(.all); |
| 80 | try archive.supportFormat(.all); | 66 | try archive.supportFormat(.all); |
| 81 | try archive.openFilename(tmpname, 10240); | 67 | try archive.openMemory(data); |
| 82 | 68 | ||
| 83 | while (try archive.nextHeader()) |entry_c| { | 69 | while (try archive.nextHeader()) |entry_c| { |
| 84 | var entry = entry_c; | 70 | var entry = entry_c; |