mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
TEMP: catch exception when failing to download MaxMindDB
This commit is contained in:
parent
cb3ddeca40
commit
8c8c925d1b
|
@ -25,31 +25,35 @@ class DiscourseIpInfo
|
|||
end
|
||||
|
||||
def self.mmdb_download(name)
|
||||
FileUtils.mkdir_p(path)
|
||||
begin
|
||||
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}")
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
ensure
|
||||
FileUtils.rm_rf(dest) if dest
|
||||
FileUtils.rm(tar_gz_file) if tar_gz_file
|
||||
rescue => e
|
||||
Rails.logger.warn("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
|
||||
end
|
||||
|
||||
def mmdb_load(filepath)
|
||||
|
|
Loading…
Reference in New Issue
Block a user