Skip to content

Commit 88ea677

Browse files
committed
maint<ALT>: Fix owner for the facts folder
* When retrieving facts and string them to the facts fils as yaml, the folder is created as of root, so changing them to puppet defaults.
1 parent e227c27 commit 88ea677

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/puppet/file_system/file_impl.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ def chmod(mode, path)
161161
def replace_file(path, mode = nil)
162162
begin
163163
stat = lstat(path)
164-
gid = stat.gid
165-
uid = stat.uid
164+
gid = Puppet::Type.type(:group).new(name: Puppet[:group]).exists? ? Puppet[:group] : stat.gid
165+
uid = Puppet::Type.type(:user).new(name: Puppet[:user]).exists? ? Puppet[:user] : stat.uid
166166
mode ||= stat.mode & 0o7777
167167
rescue Errno::ENOENT
168168
mode ||= 0o640

lib/puppet/indirector/yaml.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def save(request)
2626
basedir = File.dirname(file)
2727

2828
# This is quite likely a bad idea, since we're not managing ownership or modes.
29-
Dir.mkdir(basedir) unless Puppet::FileSystem.exist?(basedir)
29+
touch_dir(basedir) unless Puppet::FileSystem.exist?(basedir)
3030

3131
begin
3232
Puppet::Util::Yaml.dump(request.instance, file)
@@ -59,6 +59,15 @@ def search(request)
5959

6060
protected
6161

62+
def touch_dir(dir)
63+
Dir.mkdir(dir)
64+
65+
user = Puppet::Type.type(:user).new(name: Puppet[:user]).exists? ? Puppet[:user] : nil
66+
group = Puppet::Type.type(:group).new(name: Puppet[:group]).exists? ? Puppet[:group] : nil
67+
Puppet.debug("Fixing perms for #{user}:#{group} on #{dir}")
68+
FileUtils.chown(user, group, dir) if user || group
69+
end
70+
6271
def load_file(file)
6372
Puppet::Util::Yaml.safe_load_file(file, [model, Symbol])
6473
end

0 commit comments

Comments
 (0)