diff options
| author | 2022-04-26 00:44:24 +0300 | |
|---|---|---|
| committer | 2022-04-26 00:44:24 +0300 | |
| commit | 595477339b9e7dd696aaa31e21308f48c5a6109d (patch) | |
| tree | 96dca0017a60c40dd5437645cb11d8ff92318baf /src/Installation.zig | |
| parent | Add a missing const (diff) | |
| download | zup-595477339b9e7dd696aaa31e21308f48c5a6109d.tar.gz zup-595477339b9e7dd696aaa31e21308f48c5a6109d.tar.xz zup-595477339b9e7dd696aaa31e21308f48c5a6109d.zip | |
Add Installation.isActive, use it
Diffstat (limited to 'src/Installation.zig')
| -rw-r--r-- | src/Installation.zig | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/Installation.zig b/src/Installation.zig index 3b0382a..fb06824 100644 --- a/src/Installation.zig +++ b/src/Installation.zig | |||
| @@ -62,12 +62,13 @@ pub fn getActiveName(allocator: Allocator) !?[]u8 { | |||
| 62 | return try allocator.dupe(u8, std.fs.path.dirname(rel_path).?); | 62 | return try allocator.dupe(u8, std.fs.path.dirname(rel_path).?); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | pub fn isInstalled(allocator: Allocator, name: []const u8) !bool { | 65 | pub fn isActive(allocator: Allocator, name: []const u8) !bool { |
| 66 | var zup_data = try xdg.openDataHome(allocator, "zup"); | 66 | const active_name_opt = try getActiveName(allocator); |
| 67 | defer zup_data.close(); | 67 | if (active_name_opt) |active_name| { |
| 68 | 68 | defer allocator.free(active_name); | |
| 69 | zup_data.access(name, .{}) catch return false; | 69 | return std.mem.eql(u8, active_name, name); |
| 70 | return true; | 70 | } |
| 71 | return false; | ||
| 71 | } | 72 | } |
| 72 | 73 | ||
| 73 | pub fn getInstalledList(allocator: Allocator) !Installations { | 74 | pub fn getInstalledList(allocator: Allocator) !Installations { |
| @@ -119,6 +120,14 @@ pub fn getInstalledList(allocator: Allocator) !Installations { | |||
| 119 | return installations; | 120 | return installations; |
| 120 | } | 121 | } |
| 121 | 122 | ||
| 123 | pub fn isInstalled(allocator: Allocator, name: []const u8) !bool { | ||
| 124 | var zup_data = try xdg.openDataHome(allocator, "zup"); | ||
| 125 | defer zup_data.close(); | ||
| 126 | |||
| 127 | zup_data.access(name, .{}) catch return false; | ||
| 128 | return true; | ||
| 129 | } | ||
| 130 | |||
| 122 | pub fn getAvailableList(allocator: Allocator) !Installations { | 131 | pub fn getAvailableList(allocator: Allocator) !Installations { |
| 123 | var json_str = try curl.easyDownload(allocator, "https://ziglang.org/download/index.json"); | 132 | var json_str = try curl.easyDownload(allocator, "https://ziglang.org/download/index.json"); |
| 124 | defer allocator.free(json_str); | 133 | defer allocator.free(json_str); |