delete cache if old

This commit is contained in:
Emil Lerch 2026-01-08 20:03:42 -08:00
parent bfae3c726b
commit a79094efdc
Signed by: lobo
GPG key ID: A7B62D657EF764F8
2 changed files with 5 additions and 1 deletions

View file

@ -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);
}

View file

@ -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 {