Improved file reading error handling.
This commit is contained in:
parent
9cca6be134
commit
6e150a93c5
2 changed files with 15 additions and 6 deletions
|
@ -252,10 +252,11 @@ class Package < ApplicationModel
|
|||
# Package.reinstall( package_name )
|
||||
def self.reinstall(package_name)
|
||||
package = Package.where( :name => package_name ).first
|
||||
return if !package
|
||||
if !package
|
||||
raise "No such package '#{package_name}'"
|
||||
end
|
||||
|
||||
file = self._get_bin( package.name, package.version )
|
||||
return if !file
|
||||
self.install( :string => file, :reinstall => true )
|
||||
end
|
||||
|
||||
|
@ -345,8 +346,14 @@ class Package < ApplicationModel
|
|||
)
|
||||
|
||||
# find file
|
||||
return if !list
|
||||
list.first.store_file.data
|
||||
if !list || !list.first
|
||||
raise "No such file in storage list #{name} #{version}"
|
||||
end
|
||||
store_file = list.first.store_file
|
||||
if !store_file
|
||||
raise "No such file in storage #{name} #{version}"
|
||||
end
|
||||
store_file.data
|
||||
end
|
||||
|
||||
def self._read_file(file, fullpath = false)
|
||||
|
|
|
@ -47,14 +47,16 @@ class Store < ApplicationModel
|
|||
|
||||
def self.list(data)
|
||||
# search
|
||||
stores = Store.where( :store_object_id => Store::Object.where( :name => data[:object] ), :o_id => data[:o_id].to_i ).
|
||||
store_object_id = Store::Object.lookup( :name => data[:object] )
|
||||
stores = Store.where( :store_object_id => store_object_id, :o_id => data[:o_id].to_i ).
|
||||
order('created_at ASC, id ASC')
|
||||
return stores
|
||||
end
|
||||
|
||||
def self.remove(data)
|
||||
# search
|
||||
stores = Store.where( :store_object_id => Store::Object.where( :name => data[:object] ) ).
|
||||
store_object_id = Store::Object.lookup( :name => data[:object] )
|
||||
stores = Store.where( :store_object_id => store_object_id ).
|
||||
where( :o_id => data[:o_id] ).
|
||||
order('created_at ASC, id ASC')
|
||||
stores.each do |store|
|
||||
|
|
Loading…
Reference in a new issue