Skip to content

Commit 4408377

Browse files
Convert filename filter list to pure ruby
The linuxism of -regextype has broken healthchecks on Solaris and FreeBSD since 2016 This applies the filters to all the distros and simplifies the code. Support for regexps on filename suffixes has been dropped in favor of simplicity and verbosity. Signed-off-by: Lamont Granquist <[email protected]>
1 parent 6652b83 commit 4408377

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

lib/omnibus/health_check.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,11 @@ def health_check_aix
336336
# the bad libraries (library_name -> dependency_name -> satisfied_lib_path -> count)
337337
#
338338
def health_check_ldd
339-
regexp_ends = ".*(" + IGNORED_ENDINGS.map { |e| e.gsub(/\./, '\.') }.join("|") + ")$"
340-
regexp_patterns = IGNORED_PATTERNS.map { |e| ".*" + e.gsub(%r{/}, '\/') + ".*" }.join("|")
341-
regexp = regexp_ends + "|" + regexp_patterns
342-
343339
current_library = nil
344340
bad_libs = {}
345341
good_libs = {}
346342

347-
read_shared_libs("find #{project.install_dir}/ -type f -regextype posix-extended ! -regex '#{regexp}'", "xargs ldd") do |line|
343+
read_shared_libs("find #{project.install_dir}/ -type f", "xargs ldd") do |line|
348344
case line
349345
when /^(.+):$/
350346
current_library = Regexp.last_match[1]
@@ -412,14 +408,18 @@ def read_shared_libs(find_command, ldd_command, &output_proc)
412408
# construct the list of files to check
413409
#
414410

415-
find_output = shellout!(find_command).stdout
411+
find_output = shellout!(find_command).stdout.lines
412+
413+
find_output.reject! { |file| IGNORED_ENDINGS.any? { |ending| file.end_with?(ending) } }
414+
415+
find_output.reject! { |file| IGNORED_SUBSTRINGS.any? { |substr| file.include?(substr) } }
416416

417417
if find_output.empty?
418418
# probably the find_command is busted, it should never be empty or why are you using omnibus?
419419
raise "Internal Error: Health Check found no lines"
420420
end
421421

422-
if find_output.lines.any? { |file| file !~ Regexp.new(project.install_dir) }
422+
if find_output.any? { |file| file !~ Regexp.new(project.install_dir) }
423423
# every file in the find output should be within the install_dir
424424
raise "Internal Error: Health Check lines not matching the install_dir"
425425
end
@@ -429,7 +429,7 @@ def read_shared_libs(find_command, ldd_command, &output_proc)
429429
#
430430

431431
# this command will typically fail if the last file isn't a valid lib/binary which happens often
432-
ldd_output = shellout(ldd_command, input: find_output).stdout
432+
ldd_output = shellout(ldd_command, input: find_output.join("\n")).stdout
433433

434434
#
435435
# do the output process to determine if the files are good or bad

lib/omnibus/whitelist.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# Copyright 2012-2020, Chef Software Inc.
2+
# Copyright:: Copyright (c) Chef Software Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -181,24 +181,29 @@
181181

182182
IGNORED_ENDINGS = %w{
183183
.TXT
184-
.[ch]
185-
.[ch]pp
186-
.[eh]rl
187184
.app
188185
.appup
189186
.bat
190187
.beam
188+
.c
191189
.cc
192190
.cmake
193191
.conf
192+
.cpp
194193
.css
195-
.e*rb
194+
.erb
195+
.erl
196196
.feature
197197
.gemspec
198198
.gif
199199
.gitignore
200200
.gitkeep
201-
.h*h
201+
.h
202+
.h
203+
.hh
204+
.hpp
205+
.hrl
206+
.html
202207
.jar
203208
.java
204209
.jpg
@@ -219,10 +224,13 @@
219224
.png
220225
.pod
221226
.properties
222-
.py[oc]*
223-
.r*html
227+
.py
228+
.pyc
229+
.pyo
224230
.rake
231+
.rb
225232
.rdoc
233+
.rhtml
226234
.ri
227235
.rst
228236
.scss
@@ -243,7 +251,7 @@
243251
license
244252
}.freeze
245253

246-
IGNORED_PATTERNS = %w{
254+
IGNORED_SUBSTRINGS = %w{
247255
/build_info/
248256
/licenses/
249257
/LICENSES/

0 commit comments

Comments
 (0)