summaryrefslogtreecommitdiff
path: root/chef
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2009-02-13 00:08:47 +0000
committerBryan McLellan <btm@loftninjas.org>2009-02-13 01:52:31 +0000
commit85ee337fc1678ee0946751323de7388371a1a067 (patch)
treec4b998233e6b4e1aaf0b5c4d95f2fad9c6eda5e3 /chef
parenta607b4d81115b5ea00c28fd397d5c137197a34b4 (diff)
downloadchef-85ee337fc1678ee0946751323de7388371a1a067.tar.gz
Add some dpkg exception handling
Diffstat (limited to 'chef')
-rw-r--r--chef/lib/chef/provider/package/dpkg.rb50
1 files changed, 23 insertions, 27 deletions
diff --git a/chef/lib/chef/provider/package/dpkg.rb b/chef/lib/chef/provider/package/dpkg.rb
index 0893583232..7bea515187 100644
--- a/chef/lib/chef/provider/package/dpkg.rb
+++ b/chef/lib/chef/provider/package/dpkg.rb
@@ -23,22 +23,36 @@ require 'chef/resource/package'
class Chef
class Provider
class Package
- class Dpkg < Chef::Provider::Package
+ class Dpkg < Chef::Provider::Package
def load_current_resource
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@new_resource.version(nil)
- # Get information from the package supplied
- Chef::Log.debug("Checking dpkg status for #{@new_resource.package_name}")
- status = popen4("dpkg-deb -W #{@new_resource.source}") do |pid, stdin, stdout, stderr|
- stdout.each do |line|
- case line
- when /([\w\d]+)\t([\w\d.-]+)/
- @current_resource.package_name($1)
- @new_resource.version($2)
+ Chef::Log.debug("SOURCE: #{@new_resource.source}")
+ if @new_resource.source
+ Chef::Log.debug("FOUND SOURCE!!!!")
+ unless ::File.exists?(@new_resource.source)
+ raise Chef::Exception::Package, "Package #{@new_resource.name} not found: #{@new_resource.package_name}"
+ end
+
+ # Get information from the package if supplied
+ Chef::Log.debug("Checking dpkg status for #{@new_resource.package_name}")
+ status = popen4("dpkg-deb -W #{@new_resource.source}") do |pid, stdin, stdout, stderr|
+ stdout.each do |line|
+ case line
+ when /([\w\d]+)\t([\w\d.-]+)/
+ @current_resource.package_name($1)
+ @new_resource.version($2)
+ end
end
end
+ else
+ # if the source was not set, and we're installing, fail
+ if @new_resource.actions.has_key?(:install)
+ raise Chef::Exception::Package, "Source for package #{@new_resource.name} required for action install"
+ end
+ @current_resource.package_name(@new_resource.package_name)
end
# Check to see if it is installed
@@ -74,10 +88,6 @@ class Chef
)
end
- def upgrade_package(name, version)
- install_package(name, version)
- end
-
def remove_package(name, version)
run_command(
:command => "dpkg -r #{@new_resource.package_name}",
@@ -95,20 +105,6 @@ class Chef
}
)
end
-
- def preseed_package(name, version)
- preseed_file = get_preseed_file(name, version)
- if preseed_file
- Chef::Log.info("Pre-seeding #{@new_resource} with package installation instructions.")
- run_command(
- :command => "debconf-set-selections #{preseed_file}",
- :environment => {
- "DEBIAN_FRONTEND" => "noninteractive"
- }
- )
- end
- end
-
end
end
end