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

Conversation

mhashizume
Copy link
Contributor

When the user type was originally created, it used methods from the ETC module. That code was removed in 12452ee in 2006, so we no longer need to require ETC.

When the user type was originally created, it used methods from the ETC
module. That code was removed in 12452ee in 2006, so we no longer need
to require ETC.
@mhashizume mhashizume added the maintenance Maintenance chores are excluded from changelogs label May 14, 2024
@mhashizume mhashizume requested a review from a team as a code owner May 14, 2024 17:08
@@ -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'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Maintenance chores are excluded from changelogs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants