Skip to content

A platform for community discussion. Free, open, simple.

FIX: MaxMind DB file not downloading correctly

Sam Saffrond0630ea6eee8
diff --git a/lib/discourse_ip_info.rb b/lib/discourse_ip_info.rb
index 50c5d3854f2..6aa0f165055 100644
--- a/lib/discourse_ip_info.rb
+++ b/lib/discourse_ip_info.rb
@@ -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