Skip to content

Commit 28c8a65

Browse files
committed
(GH-552) Fix home directory evaluation
Prior to this commit the module would fail when executed under the context of systemd. This was because Dir.home tries to expand `~` when no UID is passed. However the HOME environment variable is not available when the agent is executed by systemd resulting in the following error: `Could not evaluate: couldn't find login name -- expanding ~` This commit fixes this by reverting to using Etc.getpwuid so that we can retrieve the home dir from the uid of the current process. For consistency, retrieval of home dirs for a given user has also been changed to use Etc.getpwnam.
1 parent c23a38e commit 28c8a65

File tree

1 file changed

+3
-2
lines changed
  • lib/puppet/provider/vcsrepo

1 file changed

+3
-2
lines changed

lib/puppet/provider/vcsrepo/git.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,11 @@ def exec_git(*args)
650650
exec_args = {
651651
failonfail: true,
652652
combine: true,
653-
custom_environment: { 'HOME' => Dir.home },
653+
custom_environment: { 'HOME' => Etc.getpwuid(Process.uid).dir },
654654
}
655+
655656
if @resource.value(:user) && @resource.value(:user) != Facter['id'].value
656-
exec_args[:custom_environment] = { 'HOME' => Dir.home(@resource.value(:user)) }
657+
exec_args[:custom_environment] = { 'HOME' => Etc.getpwnam(@resource.value(:user)).dir }
657658
exec_args[:uid] = @resource.value(:user)
658659
end
659660
Puppet::Util::Execution.execute([:git, args], **exec_args)

0 commit comments

Comments
 (0)