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:
Sam Saffron 2020-01-05 22:08:13 +11:00
parent 9a6606dd30
commit d0630ea6ee

View File

@ -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