From a51e2271af2db71cf9a82c9c9efd53182d173ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 24 May 2019 15:13:19 +0200 Subject: [PATCH] DEV: remove temporary rescue when downloading MaxMindDB follow-up 8c8c925d1b0eb36e3973af98b17bbfed5d61b3b4 --- lib/discourse_ip_info.rb | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/lib/discourse_ip_info.rb b/lib/discourse_ip_info.rb index 5ae31129cf9..c2c72db9081 100644 --- a/lib/discourse_ip_info.rb +++ b/lib/discourse_ip_info.rb @@ -25,35 +25,31 @@ class DiscourseIpInfo end def self.mmdb_download(name) - begin - FileUtils.mkdir_p(path) + FileUtils.mkdir_p(path) - uri = URI("https://geolite.maxmind.com/download/geoip/database/#{name}.tar.gz") + uri = URI("https://geolite.maxmind.com/download/geoip/database/#{name}.tar.gz") - tar_gz_file = Tempfile.new - tar_gz_file.binmode - tar_gz_file.write(Net::HTTP.get(uri)) - tar_gz_file.close + tar_gz_file = Tempfile.new + tar_gz_file.binmode + tar_gz_file.write(Net::HTTP.get(uri)) + tar_gz_file.close - dest = File.join(Dir.tmpdir, "maxmind_#{SecureRandom.hex}") - FileUtils.mkdir_p(dest) + dest = File.join(Dir.tmpdir, "maxmind_#{SecureRandom.hex}") + FileUtils.mkdir_p(dest) - Discourse::Utils.execute_command('tar', '-xzvf', tar_gz_file.path, "-C", dest) + Discourse::Utils.execute_command('tar', '-xzvf', tar_gz_file.path, "-C", dest) - Dir.glob("#{dest}/**/*.mmdb").each do |path| - if path.include?(name) - FileUtils.mv(path, mmdb_path(name)) - else - Rails.logger.warn("Skipping unknown mmdb file during ip database update #{path}") - end + Dir.glob("#{dest}/**/*.mmdb").each do |path| + if path.include?(name) + FileUtils.mv(path, mmdb_path(name)) + else + Rails.logger.warn("Skipping unknown mmdb file during ip database update #{path}") end - - rescue => e - STDERR.puts("There was an error downloading MaxMindDB (#{name}): #{e}") - ensure - FileUtils.rm_rf(dest) if dest - FileUtils.rm(tar_gz_file) if tar_gz_file end + + ensure + FileUtils.rm_rf(dest) if dest + FileUtils.rm(tar_gz_file) if tar_gz_file end def mmdb_load(filepath)