This patch (which is a slightly cleaned up version of the one one
the ticket) appears to do the following:

* Change /var/db/.puppet_appdmg_installed_#{name} (dbfile) to yaml
  format so it can store structured data.
* Add a list of files to dbfile
* Change installapp to add the app to the file list in dbfile (i.e.,
  read the list if it's there, add the app to the list if the app
  isn't there already, and write it out).
* Add an uninstall which uses the list in the dbfile to determine
  what apps to remove and then deletes the dbfile.
* Rename methods from (.*)pkgdmg to \1appdmg.
* Change errors from self.fail to raising Puppet::Error
* Makes it an error to install without an app name.

Signed-off-by: Markus Roberts <[email protected]>
---
 lib/puppet/provider/package/appdmg.rb |   48 +++++++++++++++++++++++++-------
 1 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/lib/puppet/provider/package/appdmg.rb 
b/lib/puppet/provider/package/appdmg.rb
index 48c8f5e..2f3aa39 100644
--- a/lib/puppet/provider/package/appdmg.rb
+++ b/lib/puppet/provider/package/appdmg.rb
@@ -13,10 +13,12 @@
 # in /var/db/.puppet_appdmg_installed_<name>
 
 require 'puppet/provider/package'
+require 'yaml'
+require "FileUtils"
 
 Puppet::Type.type(:package).provide(:appdmg, :parent => 
Puppet::Provider::Package) do
     desc "Package management which copies application bundles to a target."
-
+    $appdmg_target = "/Applications"
     confine :operatingsystem => :darwin
 
     commands :hdiutil => "/usr/bin/hdiutil"
@@ -41,16 +43,33 @@ Puppet::Type.type(:package).provide(:appdmg, :parent => 
Puppet::Provider::Packag
 
     def self.installapp(source, name, orig_source)
         appname = File.basename(source);
-        ditto "--rsrc", source, "/Applications/#{appname}"
-        File.open("/var/db/.puppet_appdmg_installed_#{name}", "w") do |t|
-            t.print "name: '#{name}'\n"
-            t.print "source: '#{orig_source}'\n"
+        ditto "--rsrc", source, "#{$appdmg_target}/#{appname}"
+        dbfile = "/var/db/.puppet_appdmg_installed_#{name}.yaml"
+        receipthash = File.exist?(dbfile) ? YAML::load_file(dbfile) : {"files" 
=> []}
+        receipthash["name"] = name
+        receipthash["source"] = orig_source
+        receipthash["files"] |= [appname]
+        File.open(dbfile,"w") { |f| f.print receipthash.to_yaml }
+    end
+
+    def self.uninstallappdmg(name)
+        dbfile = "/var/db/.puppet_appdmg_installed_#{name}.yaml"
+        unless File.exist?(dbfile)
+            raise Puppet::Error.new("App DMG Package #{name} not installed.")
+        end
+        receipthash = YAML::load_file(dbfile)
+        receipthash["files"].each do |appname|
+            FileUtils.remove_entry_secure("#{$appdmg_target}/#{appname}")
+            unless $? == 0
+                raise Puppet::Error.new("App DMG could not remove 
\"#{$appdmg_target}/#{appname}\"")
+            end
         end
+        File.unlink(dbfile)
     end
 
-    def self.installpkgdmg(source, name)
+    def self.installappdmg(source, name)
         unless source =~ /\.dmg$/i
-            self.fail "Mac OS X PKG DMG's must specificy a source string 
ending in .dmg"
+            raise Puppet::Error.new("Mac OS X app DMG's must specificy a 
source string ending in .dmg")
         end
         require 'open-uri'
         require 'facter/util/plist'
@@ -93,7 +112,7 @@ Puppet::Type.type(:package).provide(:appdmg, :parent => 
Puppet::Provider::Packag
     end
 
     def query
-        if 
FileTest.exists?("/var/db/.puppet_appdmg_installed...@resource[:name]}")
+        if 
FileTest.exists?("/var/db/.puppet_appdmg_installed...@resource[:name]}.yaml")
             return {:name => @resource[:name], :ensure => :present}
         else
             return nil
@@ -103,12 +122,19 @@ Puppet::Type.type(:package).provide(:appdmg, :parent => 
Puppet::Provider::Packag
     def install
         source = nil
         unless source = @resource[:source]
-            self.fail "Mac OS X PKG DMG's must specify a package source."
+            raise Puppet::Error.new("Mac OS X app DMG's must specify a package 
source.")
         end
         unless name = @resource[:name]
-            self.fail "Mac OS X PKG DMG's must specify a package name."
+            raise Puppet::Error.new("Mac OS X app DMG's must specify a package 
name.")
+        end
+        self.class.installappdmg(source,name)
+    end
+
+    def uninstall
+        unless name = @resource[:name]
+            raise Puppet::Error.new("Mac OS X app DMG's must specify a package 
name.")
         end
-        self.class.installpkgdmg(source,name)
+        self.class.uninstallappdmg(name)
     end
 end
 
-- 
1.6.4

--

You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.


Reply via email to