From 6e150a93c59d7ed24d16c66b5d8b3530df7e729b Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 10 May 2013 23:48:29 +0200 Subject: [PATCH] Improved file reading error handling. --- app/models/package.rb | 15 +++++++++++---- app/models/store.rb | 6 ++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/models/package.rb b/app/models/package.rb index 31685749a..66b173c95 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -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) diff --git a/app/models/store.rb b/app/models/store.rb index 2859a9deb..9075e8f4e 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -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|