mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:03:43 +08:00
FIX: Ensure TarReader is closed.
This commit is contained in:
parent
4555d0c598
commit
a723699519
|
@ -26,12 +26,13 @@ class DiscourseIpInfo
|
|||
|
||||
uri = URI("https://geolite.maxmind.com/download/geoip/database/#{name}.tar.gz")
|
||||
|
||||
tar_gz_file = Tempfile.new
|
||||
begin
|
||||
tar_gz_file = Tempfile.new
|
||||
tar_gz_file.binmode
|
||||
tar_gz_file.write(Net::HTTP.get(uri))
|
||||
tar_gz_file.close
|
||||
|
||||
begin
|
||||
extractor = Gem::Package::TarReader.new(Zlib::GzipReader.open(tar_gz_file.path))
|
||||
extractor.rewind
|
||||
|
||||
|
@ -39,10 +40,13 @@ class DiscourseIpInfo
|
|||
next unless entry.full_name.ends_with?(".mmdb")
|
||||
File.open(mmdb_path(name), "wb") { |f| f.write(entry.read) }
|
||||
end
|
||||
ensure
|
||||
extractor.close
|
||||
end
|
||||
|
||||
ensure
|
||||
tar_gz_file.close
|
||||
tar_gz_file.unlink
|
||||
extractor.close
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user