From 5bfeef770534c76102c29286220c4adf094e4417 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 24 May 2019 18:08:00 -0400 Subject: [PATCH] FIX: warn instead of excepting if MaxMind DBs can't be downloaded (#7600) --- lib/discourse_ip_info.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/discourse_ip_info.rb b/lib/discourse_ip_info.rb index 37b0fa2e74..ad04661c48 100644 --- a/lib/discourse_ip_info.rb +++ b/lib/discourse_ip_info.rb @@ -27,16 +27,20 @@ class DiscourseIpInfo def self.mmdb_download(name) FileUtils.mkdir_p(path) - gz_file = FileHelper.download( - "https://geolite.maxmind.com/geoip/databases/#{name}/update", - max_file_size: 100.megabytes, - tmp_file_name: "#{name}.gz" - ) + begin + gz_file = FileHelper.download( + "https://geolite.maxmind.com/geoip/databases/#{name}/update", + max_file_size: 100.megabytes, + tmp_file_name: "#{name}.gz" + ) + + Discourse::Utils.execute_command("gunzip", gz_file.path) - Discourse::Utils.execute_command("gunzip", gz_file.path) - - path = gz_file.path.sub(/\.gz\z/, "") - FileUtils.mv(path, mmdb_path(name)) + path = gz_file.path.sub(/\.gz\z/, "") + FileUtils.mv(path, mmdb_path(name)) + rescue HTTPError => e + Rails.logger.warn("MaxMindDB (#{name}) could not be downloaded: #{e}") + end ensure gz_file&.close! end