Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary ETC requirement #9348

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/puppet/type/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'etc'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One subtly is other user providers may be relying on this require without knowing it, for example hpux

while ent = Etc.getpwent() # rubocop:disable Lint/AssignmentInCondition

Also the base NameProvider which is extended by user and group providers depends on our Etc wrapper:

method = Puppet::Etc.method(:"get#{section}ent")

And our wrapper calls Etc methods without requiring 'etc' https://github.com/puppetlabs/puppet/blob/ca922ca1f7c1cbd8c28b35a59c126b39b2c90778/lib/puppet/etc.rb

Maybe we should look at these call sites:

$ git grep '^[^#:]*Etc' lib
lib/puppet/etc.rb:      @password_class ||= Struct.new(*Etc::Passwd.members, *Etc::Passwd.members.map { |member| "canonical_#{member}".to_sym })
lib/puppet/etc.rb:      @group_class ||= Struct.new(*Etc::Group.members, *Etc::Group.members.map { |member| "canonical_#{member}".to_sym })
lib/puppet/etc.rb:      new_struct = struct.is_a?(Etc::Passwd) ? puppet_etc_passwd_class.new : puppet_etc_group_class.new
lib/puppet/feature/base.rb:  !Etc.getpwuid(0).nil? && Puppet.features.syslog?
lib/puppet/file_system/uniquefile.rb:  @@systmpdir ||= defined?(Etc.systmpdir) ? Etc.systmpdir : '/tmp'
lib/puppet/provider/file/posix.rb:      user = Etc.getpwuid(id)
lib/puppet/provider/file/posix.rb:      group = Etc.getgrgid(id)
lib/puppet/provider/group/groupadd.rb:        Etc.getpwnam(user.strip)
lib/puppet/provider/nameservice.rb:              "Cannot determine Etc section without a resource type"
lib/puppet/provider/user/hpux.rb:    while ent = Etc.getpwent() # rubocop:disable Lint/AssignmentInCondition
lib/puppet/provider/user/hpux.rb:    Etc.endpwent()
lib/puppet/provider/user/hpux.rb:    ent = Etc.getpwnam(resource.name)
lib/puppet/type/exec.rb:      Etc.getpwuid(Process.uid).name
lib/puppet/util/posix.rb:      Etc.send(method, id).send(field)
lib/puppet/util/posix.rb:    Etc.send(type) do |object|
lib/puppet/util/suidmanager.rb:      gid = Etc.getpwuid(uid).gid
lib/puppet/util/suidmanager.rb:    pwent = Etc.getpwuid(uid)

And make sure each of those files contain require 'etc'?

require_relative '../../puppet/parameter/boolean'
require_relative '../../puppet/property/list'
require_relative '../../puppet/property/ordered_list'
Expand Down