Skip to content

Commit

Permalink
Fix a race in ijar_test.
Browse files Browse the repository at this point in the history
Detecting a string in bash with the pattern `echo "source text" | grep -q "string to match"` may have false negatives. Indeed, if the `grep -q` command finds its match early and exits successfully but quickly, the `echo` command will be killed by `SIGPIPE`, making the entire pipeline fail. Avoid this problem by replacing `echo` with heredoc strings.

Partial commit for third_party/*, see #16788.

Signed-off-by: Sunil Gowroji <sgowroji@google.com>
  • Loading branch information
benjaminp authored and sgowroji committed Nov 18, 2022
1 parent 94355b1 commit 44918c5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions third_party/ijar/test/ijar_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ function check_consistent_file_contents() {
local actual="$(cat $1 | ${MD5SUM} | awk '{ print $1; }')"
local filename="$(echo $1 | ${MD5SUM} | awk '{ print $1; }')"
local expected="$actual"
if (echo "${expected_output}" | grep -q "^${filename} "); then
echo "${expected_output}" | grep -q "^${filename} ${actual}$" || {
if (grep -q "^${filename} " <<<"${expected_output}"); then
grep -q "^${filename} ${actual}$" <<<"${expected_output}" || {
ls -l "$1"
fail "output file contents differ"
}
Expand Down

0 comments on commit 44918c5

Please sign in to comment.