mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:49:06 +08:00
FIX: MaxMind DB file not downloading correctly
Previously we had the ability to download a simple .gz file new changes mean we have a a tar.gz file that needs some levels of fiddling to get extracted correctly
This commit is contained in:
parent
9a6606dd30
commit
d0630ea6ee
|
@ -44,11 +44,33 @@ class DiscourseIpInfo
|
|||
follow_redirect: false
|
||||
)
|
||||
|
||||
Discourse::Utils.execute_command("gunzip", gz_file.path)
|
||||
filename = File.basename(gz_file.path)
|
||||
|
||||
dir = "#{Dir.tmpdir}/#{SecureRandom.hex}"
|
||||
|
||||
Discourse::Utils.execute_command(
|
||||
"mkdir", "-p", dir
|
||||
)
|
||||
|
||||
Discourse::Utils.execute_command(
|
||||
"cp",
|
||||
gz_file.path,
|
||||
"#{dir}/#{filename}"
|
||||
)
|
||||
|
||||
Discourse::Utils.execute_command(
|
||||
"tar",
|
||||
"-xzvf",
|
||||
"#{dir}/#{filename}",
|
||||
chdir: dir
|
||||
)
|
||||
|
||||
Dir["#{dir}/**/*.mmdb"].each do |f|
|
||||
FileUtils.mv(f, mmdb_path(name))
|
||||
end
|
||||
|
||||
path = gz_file.path.sub(/\.gz\z/, "")
|
||||
FileUtils.mv(path, mmdb_path(name))
|
||||
ensure
|
||||
FileUtils.rm_r(dir, force: true) if dir
|
||||
gz_file&.close!
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user