From 28c8a65f7cc09ccb647b3c93f80f805b72cd8a96 Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Wed, 29 Jun 2022 13:38:18 +0100 Subject: [PATCH] (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. --- lib/puppet/provider/vcsrepo/git.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index f7b16e3c..45cdf7cd 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -650,10 +650,11 @@ def exec_git(*args) exec_args = { failonfail: true, combine: true, - custom_environment: { 'HOME' => Dir.home }, + custom_environment: { 'HOME' => Etc.getpwuid(Process.uid).dir }, } + if @resource.value(:user) && @resource.value(:user) != Facter['id'].value - exec_args[:custom_environment] = { 'HOME' => Dir.home(@resource.value(:user)) } + exec_args[:custom_environment] = { 'HOME' => Etc.getpwnam(@resource.value(:user)).dir } exec_args[:uid] = @resource.value(:user) end Puppet::Util::Execution.execute([:git, args], **exec_args)