Skip to content
Open
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
18 changes: 15 additions & 3 deletions lib/puppetserver/ca/utils/file_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ def self.forcibly_symlink(source, link_target)
# Symlink permissions are ignored in favor of the source's permissions,
# so we don't have to change those.
source_info = File.stat(source)
FileUtils.chown(source_info.uid, source_info.gid, link_target)
begin
FileUtils.chown(source_info.uid, source_info.gid, link_target)
rescue Errno::EPERM # rubocop:disable Lint/SuppressedException
# In rootless containers the process may lack CAP_CHOWN.
end
end

def initialize
Expand Down Expand Up @@ -93,14 +97,22 @@ def write_file(path, one_or_more_objects, mode)
f.puts object.to_s
end
end
FileUtils.chown(@user, @group, path)
begin
FileUtils.chown(@user, @group, path)
rescue Errno::EPERM # rubocop:disable Lint/SuppressedException
# In rootless containers the process may lack CAP_CHOWN.
end
end

# Warning: directory mode should be specified in DIR_MODES above
def ensure_dir(directory)
if !File.exist?(directory)
FileUtils.mkdir_p(directory, mode: DIR_MODES[directory])
FileUtils.chown(@user, @group, directory)
begin
FileUtils.chown(@user, @group, directory)
rescue Errno::EPERM # rubocop:disable Lint/SuppressedException
# In rootless containers the process may lack CAP_CHOWN.
end
end
end
end
Expand Down
Loading