@@ -6,6 +6,7 @@ const Command = enum {
66 install ,
77 setup ,
88 exists ,
9+ @"recache-master" ,
910 help ,
1011 version ,
1112};
@@ -28,6 +29,7 @@ pub fn main() !void {
2829 .install = > install (allocator , args ),
2930 .setup = > setup (allocator , args ),
3031 .exists = > exists (allocator , args ),
32+ .@"recache-master" = > recache_master (allocator ),
3133 .help = > help_menu (),
3234 .version = > version (),
3335 };
@@ -44,6 +46,7 @@ fn help_menu() !void {
4446 \\install [version] - Install a zig version
4547 \\setup [version] - First time setup (creates a config and installs the version)
4648 \\exists [version] - Check if a zig version is installed on the system
49+ \\recache-master - Re-cache the master version
4750 \\help - Outputs this help Menu
4851 \\version - Outputs zigd version
4952 \\
@@ -69,17 +72,17 @@ fn install(allocator: std.mem.Allocator, args: []const []const u8) !void {
6972 return ;
7073 }
7174
72- var zig_version = try zigdcore .ZigVersion .parse (allocator , args [2 ], & user_arg , false );
75+ const zigd_path = try zigdcore .getZigdPath (allocator );
76+ defer allocator .free (zigd_path );
77+
78+ var zig_version = try zigdcore .ZigVersion .parse (allocator , args [2 ], & user_arg , false , zigd_path , true );
7379 defer zig_version .deinitIfMasterOrZigverOrZonver (allocator );
7480
7581 try std .io .getStdOut ().writer ().print ("Installing zig version {s}\n " , .{zig_version });
7682
7783 const download_url = try zigdcore .downloadUrlFromVersion (allocator , zig_version .as_string , zig_version .source == .Master );
7884 defer allocator .free (download_url );
7985
80- const zigd_path = try zigdcore .getZigdPath (allocator );
81- defer allocator .free (zigd_path );
82-
8386 if (! try zigdcore .install_zig (allocator , download_url , zigd_path , zig_version )) {
8487 std .log .err ("Installation failed!" , .{});
8588 }
@@ -117,7 +120,7 @@ fn setup(allocator: std.mem.Allocator, args: []const []const u8) !void {
117120 }
118121 }
119122
120- var zig_version = try zigdcore .ZigVersion .parse (allocator , args [2 ], & user_arg , false );
123+ var zig_version = try zigdcore .ZigVersion .parse (allocator , args [2 ], & user_arg , false , zigd_path , true );
121124 defer zig_version .deinitIfMasterOrZigverOrZonver (allocator );
122125
123126 if (zig_version .source == .Master ) {
@@ -168,10 +171,10 @@ fn exists(allocator: std.mem.Allocator, args: []const []const u8) !void {
168171 const zigd_path = try zigdcore .getZigdPath (allocator );
169172 defer allocator .free (zigd_path );
170173
171- var zig_version = try zigdcore .ZigVersion .parse (allocator , args [2 ], & user_arg , false );
174+ var zig_version = try zigdcore .ZigVersion .parse (allocator , args [2 ], & user_arg , false , zigd_path , true );
172175 defer zig_version .deinitIfMasterOrZigverOrZonver (allocator );
173176
174- const version_path = try std .fs .path .join (allocator , &.{ zigd_path , "versions" , args [ 2 ] });
177+ const version_path = try std .fs .path .join (allocator , &.{ zigd_path , "versions" , zig_version . as_string });
175178 defer allocator .free (version_path );
176179
177180 if (try utils .isDirectory (version_path )) {
@@ -180,3 +183,19 @@ fn exists(allocator: std.mem.Allocator, args: []const []const u8) !void {
180183 try std .io .getStdOut ().writer ().writeAll ("No!\n " );
181184 }
182185}
186+
187+ fn recache_master (allocator : std.mem.Allocator ) ! void {
188+ const zigd_path = try zigdcore .getZigdPath (allocator );
189+ defer allocator .free (zigd_path );
190+
191+ const master = try zigdcore .fetchMaster (allocator , zigd_path , false );
192+ defer allocator .free (master );
193+
194+ const cache_path = try zigdcore .getCachePath (allocator , zigd_path );
195+ defer allocator .free (cache_path );
196+
197+ const cache_file = try zigdcore .getCacheFile (cache_path );
198+ defer cache_file .close ();
199+
200+ try cache_file .writer ().writeAll (master );
201+ }
0 commit comments