mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 14:03:22 +08:00
FIX: rescue mmdb download failure (#27556)
* rescue mmdb download failure If mmdb database fails to download a bootstrap fails. This is a trivial fix for that problem. A more elegant solution might check whether the dataabase was downloaded and provide a helpful error message. * linting --------- Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
This commit is contained in:
parent
9ab18ed2e3
commit
6a5ee0693d
|
@ -55,27 +55,31 @@ class DiscourseIpInfo
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
gz_file =
|
begin
|
||||||
FileHelper.download(
|
gz_file =
|
||||||
url,
|
FileHelper.download(
|
||||||
max_file_size: 100.megabytes,
|
url,
|
||||||
tmp_file_name: "#{name}.gz",
|
max_file_size: 100.megabytes,
|
||||||
validate_uri: false,
|
tmp_file_name: "#{name}.gz",
|
||||||
follow_redirect: true,
|
validate_uri: false,
|
||||||
extra_headers:,
|
follow_redirect: true,
|
||||||
)
|
extra_headers:,
|
||||||
|
)
|
||||||
|
|
||||||
filename = File.basename(gz_file.path)
|
filename = File.basename(gz_file.path)
|
||||||
|
|
||||||
dir = "#{Dir.tmpdir}/#{SecureRandom.hex}"
|
dir = "#{Dir.tmpdir}/#{SecureRandom.hex}"
|
||||||
|
|
||||||
Discourse::Utils.execute_command("mkdir", "-p", dir)
|
Discourse::Utils.execute_command("mkdir", "-p", dir)
|
||||||
|
|
||||||
Discourse::Utils.execute_command("cp", gz_file.path, "#{dir}/#{filename}")
|
Discourse::Utils.execute_command("cp", gz_file.path, "#{dir}/#{filename}")
|
||||||
|
|
||||||
Discourse::Utils.execute_command("tar", "-xzvf", "#{dir}/#{filename}", chdir: dir)
|
Discourse::Utils.execute_command("tar", "-xzvf", "#{dir}/#{filename}", chdir: dir)
|
||||||
|
|
||||||
Dir["#{dir}/**/*.mmdb"].each { |f| FileUtils.mv(f, mmdb_path(name)) }
|
Dir["#{dir}/**/*.mmdb"].each { |f| FileUtils.mv(f, mmdb_path(name)) }
|
||||||
|
rescue => e
|
||||||
|
Discourse.warn_exception(e, message: "MaxMind database download failed.")
|
||||||
|
end
|
||||||
ensure
|
ensure
|
||||||
FileUtils.rm_r(dir, force: true) if dir
|
FileUtils.rm_r(dir, force: true) if dir
|
||||||
gz_file&.close!
|
gz_file&.close!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user