[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:34:20 UTC 2010


The following commit has been merged in the upstream branch:
commit a90bcb08c3dc0a3c777f8a6c7d75cb6533a8804d
Author: David Schmitt <david at dasz.at>
Date:   Tue May 11 18:30:49 2010 +0200

    Start extracting the owner managment for files into providers

diff --git a/lib/puppet/provider/file/posix.rb b/lib/puppet/provider/file/posix.rb
new file mode 100644
index 0000000..131fd54
--- /dev/null
+++ b/lib/puppet/provider/file/posix.rb
@@ -0,0 +1,109 @@
+Puppet::Type.type(:file).provide :posix do
+    desc "Uses POSIX functionality to manage file's users and rights."
+
+    confine :feature => :posix
+
+    include Puppet::Util::POSIX
+    include Puppet::Util::Warnings
+
+    require 'etc'
+
+    def id2name(id)
+        return id.to_s if id.is_a?(Symbol)
+        return nil if id > Puppet[:maximum_uid].to_i
+
+        begin
+            user = Etc.getpwuid(id)
+        rescue TypeError
+            return nil
+        rescue ArgumentError
+            return nil
+        end
+
+        if user.uid == ""
+            return nil
+        else
+            return user.name
+        end
+    end
+
+    def insync?(current, should)
+        return true unless should
+
+        should.each do |value|
+            if value =~ /^\d+$/
+                uid = Integer(value)
+            elsif value.is_a?(String)
+                fail "Could not find user %s" % value unless uid = uid(value)
+            else
+                uid = value
+            end
+
+            return true if uid == current
+        end
+
+        unless Puppet::Util::SUIDManager.uid == 0
+            warnonce "Cannot manage ownership unless running as root"
+            return true
+        end
+
+        return false
+    end
+
+    # Determine if the user is valid, and if so, return the UID
+    def validuser?(value)
+        begin
+            number = Integer(value)
+            return number
+        rescue ArgumentError
+            number = nil
+        end
+        if number = uid(value)
+            return number
+        else
+            return false
+        end
+    end
+    
+    def retrieve(resource)
+        unless stat = resource.stat(false)
+            return :absent
+        end
+
+        currentvalue = stat.uid
+
+        # On OS X, files that are owned by -2 get returned as really
+        # large UIDs instead of negative ones.  This isn't a Ruby bug,
+        # it's an OS X bug, since it shows up in perl, too.
+        if currentvalue > Puppet[:maximum_uid].to_i
+            self.warning "Apparently using negative UID (%s) on a platform that does not consistently handle them" % currentvalue
+            currentvalue = :silly
+        end
+
+        return currentvalue
+    end
+    
+    def sync(path, links, should)
+        # Set our method appropriately, depending on links.
+        if links == :manage
+            method = :lchown
+        else
+            method = :chown
+        end
+
+        uid = nil
+        should.each do |user|
+            break if uid = validuser?(user)
+        end
+
+        raise Puppet::Error, "Could not find user(s) %s" % @should.join(",") unless uid
+
+        begin
+            File.send(method, uid, nil, path)
+        rescue => detail
+            raise Puppet::Error, "Failed to set owner to '%s': %s" % [uid, detail]
+        end
+
+        return :file_changed
+    end
+end
diff --git a/lib/puppet/provider/file/win32.rb b/lib/puppet/provider/file/win32.rb
new file mode 100644
index 0000000..45a36f2
--- /dev/null
+++ b/lib/puppet/provider/file/win32.rb
@@ -0,0 +1,78 @@
+Puppet::Type.type(:file).provide :win32 do
+    desc "Uses Win32 functionality to manage file's users and rights."
+
+    confine :feature => :win32
+
+    include Puppet::Util::Warnings
+
+    require 'sys/admin'
+    
+    def id2name(id)
+        return id.to_s if id.is_a?(Symbol)
+        return nil if id > Puppet[:maximum_uid].to_i
+        # should translate ID numbers to usernames
+        return id
+    end
+
+    def insync?(current, should)
+        return true unless should
+
+        should.each do |value|
+            if value =~ /^\d+$/
+                uid = Integer(value)
+            elsif value.is_a?(String)
+                fail "Could not find user %s" % value unless uid = uid(value)
+            else
+                uid = value
+            end
+
+            return true if uid == current
+        end
+
+        unless Puppet::Util::SUIDManager.uid == 0
+            warnonce "Cannot manage ownership unless running as root"
+            return true
+        end
+
+        return false
+    end
+
+    # Determine if the user is valid, and if so, return the UID
+    def validuser?(value)
+        info "Is '%s' a valid user?" % value
+        return 0
+        begin
+            number = Integer(value)
+            return number
+        rescue ArgumentError
+            number = nil
+        end
+        if number = uid(value)
+            return number
+        else
+            return false
+        end
+    end
+
+    def retrieve(resource)
+        unless stat = resource.stat(false)
+            return :absent
+        end
+
+        currentvalue = stat.uid
+
+        # On OS X, files that are owned by -2 get returned as really
+        # large UIDs instead of negative ones.  This isn't a Ruby bug,
+        # it's an OS X bug, since it shows up in perl, too.
+        if currentvalue > Puppet[:maximum_uid].to_i
+            self.warning "Apparently using negative UID (%s) on a platform that does not consistently handle them" % currentvalue
+            currentvalue = :silly
+        end
+
+        return currentvalue
+    end
+
+    def sync(path, links, should)
+        info("should set '%s'%%owner to '%s'" % [path, should])
+    end
+end
diff --git a/lib/puppet/type/file/owner.rb b/lib/puppet/type/file/owner.rb
index 2b53092..519bb12 100755
--- a/lib/puppet/type/file/owner.rb
+++ b/lib/puppet/type/file/owner.rb
@@ -1,73 +1,17 @@
 module Puppet
     Puppet::Type.type(:file).newproperty(:owner) do
-        include Puppet::Util::POSIX
-        include Puppet::Util::Warnings
-
-        require 'etc'
+        
         desc "To whom the file should belong.  Argument can be user name or
             user ID."
         @event = :file_changed
 
-        def id2name(id)
-            return id.to_s if id.is_a?(Symbol)
-            return nil if id > Puppet[:maximum_uid].to_i
-
-            begin
-                user = Etc.getpwuid(id)
-            rescue TypeError
-                return nil
-            rescue ArgumentError
-                return nil
-            end
-
-            if user.uid == ""
-                return nil
-            else
-                return user.name
-            end
-        end
-
         def insync?(current)
-            return true unless should
-
-            @should.each do |value|
-                if value =~ /^\d+$/
-                    uid = Integer(value)
-                elsif value.is_a?(String)
-                    fail "Could not find user %s" % value unless uid = uid(value)
-                else
-                    uid = value
-                end
-
-                return true if uid == current
-            end
-
-            unless Puppet.features.root?
-                warnonce "Cannot manage ownership unless running as root"
-                return true
-            end
-
-            return false
-        end
-
-        # Determine if the user is valid, and if so, return the UID
-        def validuser?(value)
-            begin
-                number = Integer(value)
-                return number
-            rescue ArgumentError
-                number = nil
-            end
-            if number = uid(value)
-                return number
-            else
-                return false
-            end
+            provider.insync?(current, @should)
         end
 
         # We want to print names, not numbers
         def is_to_s(currentvalue)
-            id2name(currentvalue) || currentvalue
+            provider.id2name(currentvalue) || currentvalue
         end
 
         def should_to_s(newvalue = @should)
@@ -75,7 +19,7 @@ module Puppet
             when Symbol
                 newvalue.to_s
             when Integer
-                id2name(newvalue) || newvalue
+                provider.id2name(newvalue) || newvalue
             when String
                 newvalue
             else
@@ -88,7 +32,7 @@ module Puppet
             if self.should
                 @should = @should.collect do |val|
                     unless val.is_a?(Integer)
-                        if tmp = validuser?(val)
+                        if tmp = provider.validuser?(val)
                             val = tmp
                         else
                             raise "Could not find user %s" % val
@@ -98,46 +42,11 @@ module Puppet
                     end
                 end
             end
-
-            unless stat = @resource.stat(false)
-                return :absent
-            end
-
-            currentvalue = stat.uid
-
-            # On OS X, files that are owned by -2 get returned as really
-            # large UIDs instead of negative ones.  This isn't a Ruby bug,
-            # it's an OS X bug, since it shows up in perl, too.
-            if currentvalue > Puppet[:maximum_uid].to_i
-                self.warning "Apparently using negative UID (%s) on a platform that does not consistently handle them" % currentvalue
-                currentvalue = :silly
-            end
-
-            return currentvalue
+            return provider.retrieve(@resource)
         end
 
         def sync
-            # Set our method appropriately, depending on links.
-            if resource[:links] == :manage
-                method = :lchown
-            else
-                method = :chown
-            end
-
-            uid = nil
-            @should.each do |user|
-                break if uid = validuser?(user)
-            end
-
-            raise Puppet::Error, "Could not find user(s) %s" % @should.join(",") unless uid
-
-            begin
-                File.send(method, uid, nil, @resource[:path])
-            rescue => detail
-                raise Puppet::Error, "Failed to set owner to '%s': %s" % [uid, detail]
-            end
-
-            return :file_changed
+            return provider.sync(resource[:path], resource[:links], @should)
         end
     end
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list