Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions lib/puppet/file_system/file_impl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def chmod(mode, path)
def replace_file(path, mode = nil)
begin
stat = lstat(path)
gid = stat.gid
uid = stat.uid
gid = Puppet::Type.type(:group).new(name: Puppet[:group]).exists? ? Puppet[:group] : stat.gid
uid = Puppet::Type.type(:user).new(name: Puppet[:user]).exists? ? Puppet[:user] : stat.uid
mode ||= stat.mode & 0o7777
rescue Errno::ENOENT
mode ||= 0o640
Expand Down
11 changes: 10 additions & 1 deletion lib/puppet/indirector/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def save(request)
basedir = File.dirname(file)

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

begin
Puppet::Util::Yaml.dump(request.instance, file)
Expand Down Expand Up @@ -59,6 +59,15 @@ def search(request)

protected

def touch_dir(dir)
Dir.mkdir(dir)

user = Puppet::Type.type(:user).new(name: Puppet[:user]).exists? ? Puppet[:user] : nil
group = Puppet::Type.type(:group).new(name: Puppet[:group]).exists? ? Puppet[:group] : nil
Puppet.debug("Fixing perms for #{user}:#{group} on #{dir}")
FileUtils.chown(user, group, dir) if user || group
end

def load_file(file)
Puppet::Util::Yaml.safe_load_file(file, [model, Symbol])
end
Expand Down