From fd7976e7fd1e52f321b50345f1b4efe9c84169c6 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Wed, 27 Nov 2013 14:43:35 -0800 Subject: [PATCH] fix(test_image_content): Add test for /usr file conflicts. --- build_library/test_image_content.sh | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/build_library/test_image_content.sh b/build_library/test_image_content.sh index 2a4c660db8..1389e936a7 100644 --- a/build_library/test_image_content.sh +++ b/build_library/test_image_content.sh @@ -2,6 +2,37 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +# Files that are known to conflict with /usr but are OK because they +# are already fixed by toggling the symlink-usr USE flag. +USR_CONFLICT_WHITELIST=( + /bin/awk + /bin/basename + /bin/chroot + /bin/cut + /bin/dir + /bin/dirname + /bin/du + /bin/env + /bin/expr + /bin/gawk + /bin/head + /bin/mkfifo + /bin/mktemp + /bin/passwd + /bin/readlink + /bin/seq + /bin/sleep + /bin/sort + /bin/tail + /bin/touch + /bin/tr + /bin/tty + /bin/uname + /bin/vdir + /bin/wc + /bin/yes +) + test_image_content() { local root="$1" local returncode=0 @@ -55,5 +86,29 @@ test_image_content() { fi fi + # Check that there are no conflicts between /* and /usr/* + # TODO(marineam): Before symlinking to /usr this test will need to be + # rewritten to query the package database instead of the filesystem. + local check_dir + for check_dir in "${root}"/usr/*; do + if [[ ! -d "${check_dir}" || -h "${check_dir}" ]]; then + continue + fi + for check_file in "${check_dir}"/*; do + root_file="${root}${check_file##*/usr}" + trimmed_path="${root_file#${root}}" + local whitelist + for whitelist in "${USR_CONFLICT_WHITELIST[@]}"; do + if [[ "${trimmed_path}" == "${whitelist}" ]]; then + continue 2 + fi + done + if [[ -e "${root_file}" || -h "${root_file}" ]]; then + # TODO(marineam): make fatal before switching to symlinks + warn "test_image_content: ${root_file#${root}} conflicts with /usr" + fi + done + done + return $returncode }