Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize fcontext parsing methods #385

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
23 changes: 11 additions & 12 deletions lib/puppet/provider/selinux_fcontext/semanage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ def self.file_type_map(val)
end

def self.parse_fcontext_lines(lines)
ret = []
lines.each do |line|
lines.filter_map do |line|
next if line.strip.empty?
next if line =~ %r{^#}
next if line.start_with?('#')

split = line.split(%r{\s+})
if split.length == 2
Expand All @@ -45,16 +44,16 @@ def self.parse_fcontext_lines(lines)
user = range = role = nil
end
ft = file_type_map(file_type)
ret.push(new(ensure: :present,
name: "#{path_spec}_#{ft}",
pathspec: path_spec,
seltype: type,
seluser: user,
selrole: role,
selrange: range,
file_type: ft))

new(ensure: :present,
name: "#{path_spec}_#{ft}",
pathspec: path_spec,
seltype: type,
seluser: user,
selrole: role,
selrange: range,
file_type: ft)
end
ret
end

def self.parse_fcontext_file(path)
Expand Down
13 changes: 6 additions & 7 deletions lib/puppet/provider/selinux_fcontext_equivalence/semanage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
mk_resource_methods

def self.parse_fcontext_subs_lines(lines)
ret = []
lines.each do |line|
lines.filter_map do |line|
next if line.strip.empty?
next if line =~ %r{^#}
next if line.start_with?('#')

source, target = line.split(%r{\s+})
ret.push(new(ensure: :present,
name: source,
target: target))

new(ensure: :present,
name: source,
target: target)
end
ret
end

def self.instances
Expand Down