Sha256: f466a28ff0ca6410958782feca1ccadb9b3304cd58c04c6645cc5b57c72ccb4b

Contents?: true

Size: 1.5 KB

Versions: 32

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

require_relative '../../../puppet/util/posix'

module Puppet
  # Manage file group ownership.
  Puppet::Type.type(:file).newproperty(:group) do
    desc <<-EOT
      Which group should own the file.  Argument can be either a group
      name or a group ID.

      On Windows, a user (such as "Administrator") can be set as a file's group
      and a group (such as "Administrators") can be set as a file's owner;
      however, a file's owner and group shouldn't be the same. (If the owner
      is also the group, files with modes like `"0640"` will cause log churn, as
      they will always appear out of sync.)
    EOT

    validate do |group|
      raise(Puppet::Error, "Invalid group name '#{group.inspect}'") unless group and group != ""
    end

    def insync?(current)
      # We don't want to validate/munge groups until we actually start to
      # evaluate this property, because they might be added during the catalog
      # apply.
      @should.map! do |val|
        gid = provider.name2gid(val)
        if gid
          gid
        elsif provider.resource.noop?
          return false
        else
          raise "Could not find group #{val}"
        end
      end

      @should.include?(current)
    end

    # We want to print names, not numbers
    def is_to_s(currentvalue) # rubocop:disable Naming/PredicateName
      super(provider.gid2name(currentvalue) || currentvalue)
    end

    def should_to_s(newvalue)
      super(provider.gid2name(newvalue) || newvalue)
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/type/file/group.rb
puppet-8.10.0-x86-mingw32 lib/puppet/type/file/group.rb
puppet-8.10.0-x64-mingw32 lib/puppet/type/file/group.rb
puppet-8.10.0-universal-darwin lib/puppet/type/file/group.rb
puppet-8.9.0 lib/puppet/type/file/group.rb
puppet-8.9.0-x86-mingw32 lib/puppet/type/file/group.rb
puppet-8.9.0-x64-mingw32 lib/puppet/type/file/group.rb
puppet-8.9.0-universal-darwin lib/puppet/type/file/group.rb
puppet-8.8.1 lib/puppet/type/file/group.rb
puppet-8.8.1-x86-mingw32 lib/puppet/type/file/group.rb
puppet-8.8.1-x64-mingw32 lib/puppet/type/file/group.rb
puppet-8.8.1-universal-darwin lib/puppet/type/file/group.rb
puppet-8.7.0 lib/puppet/type/file/group.rb
puppet-8.7.0-x86-mingw32 lib/puppet/type/file/group.rb
puppet-8.7.0-x64-mingw32 lib/puppet/type/file/group.rb
puppet-8.7.0-universal-darwin lib/puppet/type/file/group.rb
puppet-8.6.0 lib/puppet/type/file/group.rb
puppet-8.6.0-x86-mingw32 lib/puppet/type/file/group.rb
puppet-8.6.0-x64-mingw32 lib/puppet/type/file/group.rb
puppet-8.6.0-universal-darwin lib/puppet/type/file/group.rb