Added Package.reinstall().
This commit is contained in:
parent
51ab301745
commit
245f9410bf
1 changed files with 26 additions and 12 deletions
|
@ -179,12 +179,14 @@ class Package < ApplicationModel
|
||||||
# verify if package can get installed
|
# verify if package can get installed
|
||||||
package_db = Package.where( :name => meta[:name] ).first
|
package_db = Package.where( :name => meta[:name] ).first
|
||||||
if package_db
|
if package_db
|
||||||
|
if !data[:reinstall]
|
||||||
if Gem::Version.new( package_db.version ) == Gem::Version.new( meta[:version] )
|
if Gem::Version.new( package_db.version ) == Gem::Version.new( meta[:version] )
|
||||||
raise "Package '#{meta[:name]}-#{meta[:version]}' already installed!"
|
raise "Package '#{meta[:name]}-#{meta[:version]}' already installed!"
|
||||||
end
|
end
|
||||||
if Gem::Version.new( package_db.version ) > Gem::Version.new( meta[:version] )
|
if Gem::Version.new( package_db.version ) > Gem::Version.new( meta[:version] )
|
||||||
raise "Newer version (#{package_db.version}) of package '#{meta[:name]}-#{meta[:version]}' already installed!"
|
raise "Newer version (#{package_db.version}) of package '#{meta[:name]}-#{meta[:version]}' already installed!"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# uninstall old package
|
# uninstall old package
|
||||||
self.uninstall({
|
self.uninstall({
|
||||||
|
@ -196,6 +198,7 @@ class Package < ApplicationModel
|
||||||
|
|
||||||
# store package
|
# store package
|
||||||
record = Package.create( meta )
|
record = Package.create( meta )
|
||||||
|
if !data[:reinstall]
|
||||||
Store.add(
|
Store.add(
|
||||||
:object => 'Package',
|
:object => 'Package',
|
||||||
:o_id => record.id,
|
:o_id => record.id,
|
||||||
|
@ -203,6 +206,7 @@ class Package < ApplicationModel
|
||||||
:filename => meta[:name] + '-' + meta[:version] + '.zpm',
|
:filename => meta[:name] + '-' + meta[:version] + '.zpm',
|
||||||
:preferences => {},
|
:preferences => {},
|
||||||
)
|
)
|
||||||
|
end
|
||||||
|
|
||||||
# write files
|
# write files
|
||||||
package.elements.each('zpm/filelist/file') do |element|
|
package.elements.each('zpm/filelist/file') do |element|
|
||||||
|
@ -228,6 +232,16 @@ class Package < ApplicationModel
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Package.reinstall( package_name )
|
||||||
|
def self.reinstall(package_name)
|
||||||
|
package = Package.where( :name => package_name ).first
|
||||||
|
return if !package
|
||||||
|
|
||||||
|
file = self._get_bin( package.name, package.version )
|
||||||
|
return if !file
|
||||||
|
self.install( :string => file, :reinstall => true )
|
||||||
|
end
|
||||||
|
|
||||||
# Package.uninstall( :name => 'package', :version => '0.1.1' )
|
# Package.uninstall( :name => 'package', :version => '0.1.1' )
|
||||||
# Package.uninstall( :string => zpm_as_string )
|
# Package.uninstall( :string => zpm_as_string )
|
||||||
def self.uninstall( data )
|
def self.uninstall( data )
|
||||||
|
|
Loading…
Reference in a new issue