Skip to content

Commit

Permalink
Explicitly gunzip data
Browse files Browse the repository at this point in the history
In contrast to the previous comment open-uri does not decompress the stream
  • Loading branch information
lnussel committed Jul 28, 2017
1 parent 740c2d6 commit 286ddcf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/models/appdata.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
require 'open-uri'
require 'zlib'

class Appdata

def self.logger
Rails.logger
end

def self.get dist = "factory"
data = Hash.new
xml = Appdata.get_distribution dist, "oss"
Expand All @@ -16,7 +21,7 @@ def self.get dist = "factory"
def self.add_appdata data, xml
data[:apps] = Array.new unless data[:apps]
data[:categories] = Array.new unless data[:categories]
xml.xpath("/components/component").each do |app|
xml.xpath("/components/component").each do |app|
appdata = Hash.new
# Filter translated versions of name and summary out
appdata[:name] = app.xpath('name[not(@xml:lang)]').text
Expand All @@ -39,10 +44,12 @@ def self.get_distribution dist = "factory", flavour = "oss"
else
"http://download.opensuse.org/distribution/#{dist}/repo/#{flavour}/suse/setup/descr/appdata.xml.gz"
end
filename = File.join(Rails.root.join('tmp'), "appdata-" + dist + ".xml")
logger.debug("fetching appdata for #{dist}/#{flavour}")
filename = File.join(Rails.root.join('tmp'), "appdata-#{dist}-#{flavour}.xml")
open(filename, 'wb') do |file|
# Gzip data will be automatically decompressed with open-uri
file << open(appdata_url).read
# Gzip data will NOT be automatically decompressed with open-uri
# must have changed at some point in time, so decompress explicitly
file << Zlib::GzipReader.new(open(appdata_url)).read
end
xmlfile = File.open(filename)
doc = Nokogiri::XML(xmlfile)
Expand Down

0 comments on commit 286ddcf

Please sign in to comment.