<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>spec/unit/type/file/group.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,10 @@
+require 'puppet/util/posix'
+
 # Manage file group ownership.
 module Puppet
     Puppet.type(:file).newproperty(:group) do
+        include Puppet::Util::POSIX
+
         require 'etc'
         desc &quot;Which group should own the file.  Argument can be either group
             name or group ID.&quot;
@@ -43,31 +47,7 @@ module Puppet
         end
 
         def retrieve
-            if self.should
-                @should = @should.collect do |val|
-                    unless val.is_a?(Integer)
-                        if tmp = validgroup?(val)
-                            val = tmp
-                        else
-                            raise &quot;Could not find group %s&quot; % val
-                        end
-                    else
-                        val
-                    end
-                end
-            end
-            stat = @resource.stat(false)
-
-            unless stat
-                return :absent
-            end
-
-            # Set our method appropriately, depending on links.
-            if stat.ftype == &quot;link&quot; and @resource[:links] != :follow
-                @method = :lchown
-            else
-                @method = :chown
-            end
+            return :absent unless stat = resource.stat(false)
 
             currentvalue = stat.gid
 
@@ -84,12 +64,8 @@ module Puppet
 
         # Determine if the group is valid, and if so, return the GID
         def validgroup?(value)
-            if value =~ /^\d+$/
-                value = value.to_i
-            end
-        
-            if gid = Puppet::Util.gid(value)
-                return gid
+            if number = gid(value)
+                return number
             else
                 return false
             end
@@ -99,32 +75,28 @@ module Puppet
         # we'll just let it fail, but we should probably set things up so
         # that users get warned if they try to change to an unacceptable group.
         def sync
-            unless @resource.stat(false)
-                stat = @resource.stat(true)
-                currentvalue = self.retrieve
-
-                unless stat
-                    self.debug &quot;File '%s' does not exist; cannot chgrp&quot; %
-                        @resource[:path]
-                    return nil
-                end
+            # Set our method appropriately, depending on links.
+            if resource[:links] == :manage
+                method = :lchown
+            else
+                method = :chown
             end
 
             gid = nil
-            unless gid = Puppet::Util.gid(self.should)
-                raise Puppet::Error, &quot;Could not find group %s&quot; % self.should
+            @should.each do |group|
+                break if gid = validgroup?(group)
             end
 
+            raise Puppet::Error, &quot;Could not find group(s) %s&quot; % @should.join(&quot;,&quot;) unless gid
+
             begin
                 # set owner to nil so it's ignored
-                File.send(@method,nil,gid,@resource[:path])
+                File.send(method, nil, gid, resource[:path])
             rescue =&gt; detail
-                error = Puppet::Error.new( &quot;failed to chgrp %s to %s: %s&quot; %
-                    [@resource[:path], self.should, detail.message])
+                error = Puppet::Error.new( &quot;failed to chgrp %s to %s: %s&quot; % [resource[:path], gid, detail.message])
                 raise error
             end
             return :file_changed
         end
     end
 end
-</diff>
      <filename>lib/puppet/type/file/group.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>6bafd106de71d273745a12f50a3986fcc26a4992</id>
    </parent>
  </parents>
  <author>
    <name>Luke Kanies</name>
    <email>luke@madstop.com</email>
  </author>
  <url>http://github.com/jamtur01/puppet/commit/63ad84587892e9cab851cf516f7a381c5ea51f90</url>
  <id>63ad84587892e9cab851cf516f7a381c5ea51f90</id>
  <committed-date>2008-10-01T14:31:27-07:00</committed-date>
  <authored-date>2008-09-30T21:19:38-07:00</authored-date>
  <message>Refactoring and adding tests to the file group property.

Drastically simplified the class, removing a lot of obsolete
code and adding tests for nearly the whole class.

Signed-off-by: Luke Kanies &lt;luke@madstop.com&gt;</message>
  <tree>2f81cc210df0006a22ae1e4e84333b8b0abcfc02</tree>
  <committer>
    <name>James Turnbull</name>
    <email>james@lovedthanlost.net</email>
  </committer>
</commit>
