Added extra root option for build().

This commit is contained in:
Martin Edenhofer 2012-12-28 00:52:13 +01:00
parent 8a6d50d288
commit 5d6b60af26

View file

@ -5,7 +5,7 @@ class Package < ApplicationModel
def self.build(data) def self.build(data)
if data[:file] if data[:file]
xml = self._read_file( data[:file], true ) xml = self._read_file( data[:file], data[:root] || true )
package = self._parse(xml) package = self._parse(xml)
elsif data[:string] elsif data[:string]
package = self._parse( data[:string] ) package = self._parse( data[:string] )
@ -20,7 +20,7 @@ class Package < ApplicationModel
package.root.insert_after( '//zpm/description', build_host ) package.root.insert_after( '//zpm/description', build_host )
package.elements.each('zpm/filelist/file') do |element| package.elements.each('zpm/filelist/file') do |element|
location = element.attributes['location'] location = element.attributes['location']
content = self._read_file(location) content = self._read_file( location, data[:root] )
base64 = Base64.encode64(content) base64 = Base64.encode64(content)
element.text = base64 element.text = base64
end end
@ -165,10 +165,12 @@ class Package < ApplicationModel
end end
def self._read_file(file, fullpath = false) def self._read_file(file, fullpath = false)
if !fullpath if fullpath == false
location = @@root + '/' + file location = @@root + '/' + file
else elsif fullpath == true
location = file location = file
else
location = fullpath + '/' + file
end end
begin begin