summaryrefslogtreecommitdiff
path: root/src/install.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/install.zig')
-rw-r--r--src/install.zig30
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 @@
1const libarchive = @import("libarchive"); 1const libarchive = @import("libarchive");
2const curl = @import("curl");
3const std = @import("std"); 2const std = @import("std");
4const xdg = @import("xdg"); 3const xdg = @import("xdg");
5const zup = @import("root"); 4const zup = @import("root");
6 5
7const Allocator = std.mem.Allocator; 6const Allocator = std.mem.Allocator;
8const Config = zup.Config;
9const ArchiveRead = libarchive.Read; 7const ArchiveRead = libarchive.Read;
8const ArenaAllocator = std.heap.ArenaAllocator;
9const Config = zup.Config;
10const EasyHttp = zup.EasyHttp;
10const Installation = zup.Installation; 11const Installation = zup.Installation;
11const Installations = zup.Installations; 12const 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;