From a79094efdc245967788896c0eb979fec2a164e0f Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Thu, 8 Jan 2026 20:03:42 -0800 Subject: [PATCH] delete cache if old --- src/location/GeoIp.zig | 1 - src/location/Ip2location.zig | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/location/GeoIp.zig b/src/location/GeoIp.zig index accaddf..ded42ef 100644 --- a/src/location/GeoIp.zig +++ b/src/location/GeoIp.zig @@ -48,7 +48,6 @@ pub fn deinit(self: *GeoIP) void { c.MMDB_close(self.mmdb); self.allocator.destroy(self.mmdb); self.ip2location_client.deinit(); - log.debug("destroying client", .{}); self.allocator.destroy(self.ip2location_client); } diff --git a/src/location/Ip2location.zig b/src/location/Ip2location.zig index 32df3db..3968866 100644 --- a/src/location/Ip2location.zig +++ b/src/location/Ip2location.zig @@ -198,6 +198,11 @@ pub const Cache = struct { if (lines.next()) |first_line| { if (!std.mem.eql(u8, first_line, "#Ip2location:v2")) { log.warn("Cache file missing or invalid header, discarding", .{}); + file.close(); + self.file = null; + std.fs.deleteFileAbsolute(self.path) catch |e| { + log.err("error deleting {s}: {}", .{ self.path, e }); + }; return; } } else {