@@ -226,6 +226,30 @@ pub fn upgradeCmd(allocator: Allocator, args: []const []const u8, config: Config
226226 var parsed = parseUpgradeArgs (allocator , args );
227227 defer parsed .formula_names .deinit (allocator );
228228
229+ // Auto-update: fetch fresh formula data before comparing versions.
230+ {
231+ var jws_buf : [std .fs .max_path_bytes ]u8 = undefined ;
232+ const jws_path = std .fmt .bufPrint (& jws_buf , "{s}/api/formula.jws.json" , .{config .cache }) catch
233+ return error .PathTooLong ;
234+
235+ var idx_buf : [std .fs .max_path_bytes ]u8 = undefined ;
236+ const idx_path = std .fmt .bufPrint (& idx_buf , "{s}/api/formula.bru.idx" , .{config .cache }) catch
237+ return error .PathTooLong ;
238+
239+ var dir_buf : [std .fs .max_path_bytes ]u8 = undefined ;
240+ const api_dir = std .fmt .bufPrint (& dir_buf , "{s}/api" , .{config .cache }) catch
241+ return error .PathTooLong ;
242+ std .fs .cwd ().makePath (api_dir ) catch {};
243+
244+ var client = HttpClient .init (allocator );
245+ defer client .deinit ();
246+
247+ if (client .fetch ("https://formulae.brew.sh/api/formula.jws.json" , jws_path )) {
248+ // Fresh data downloaded — delete stale binary index to force rebuild.
249+ std .fs .deleteFileAbsolute (idx_path ) catch {};
250+ } else | _ | {}
251+ }
252+
229253 // Load index.
230254 var index = try Index .loadOrBuild (allocator , config .cache );
231255 // Note: do not call index.deinit() -- the index may be mmap'd (from disk)
0 commit comments