From 5addfbb61955d5fcb4e931573ad93e87169b247d Mon Sep 17 00:00:00 2001 From: Thomas Roeblitz Date: Sat, 24 Jan 2026 13:30:51 +0100 Subject: [PATCH 1/2] fix+improve check if bind mount already exists in BIND_PATHS --- eessi_container.sh | 99 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 5 deletions(-) diff --git a/eessi_container.sh b/eessi_container.sh index 9b5d28d7..94777f98 100755 --- a/eessi_container.sh +++ b/eessi_container.sh @@ -123,6 +123,74 @@ display_help() { echo " '--' to let eessi_container.sh stop parsing arguments." } +# function to parse and check bind paths +# returns: +# 0 if target found with matching source (no conflict) +# 1 if target found with different source (conflict) +# 2 if target not found +check_bind_paths_for_target() { + local search_target="$1" + local search_src="$2" + local bind_paths="$3" # typically used to pass value of $BIND_PATHS + + # handle empty BIND_PATHS + if [[ -z "${bind_paths}" ]]; then + return 2 + fi + + # split by comma and process each entry + IFS=',' read -ra BIND_ENTRIES <<< "${bind_paths}" + + for entry in "${BIND_ENTRIES[@]}"; do + # skip empty entries + [[ -z "${entry}" ]] && continue + + local bind_src bind_target + + # split entry by ':' + IFS=':' read -ra PARTS <<< "${entry}" + + bind_src="${PARTS[0]}" + + if [[ ${#PARTS[@]} -ge 2 ]]; then + bind_target="${PARTS[1]}" + else + # no target given, use src + bind_target=${bind_src} + fi + + # trim any possible whitespace + bind_src=$(echo "${bind_src}" | xargs) + bind_target=$(echo "${bind_target}" | xargs) + + [[ ${VERBOSE} -eq 1 ]] && echo "Parsed bind entry: src='${bind_src}' target='${bind_target}'" + + # check if this entry matches our target + if [[ "${bind_target}" == "${search_target}" ]]; then + # found target -> need to compare normalised sources + # try to normalise source paths, but don't fail if they don't exist (yet) + + bind_src_normalised=$(readlink -f "${bind_src}" 2>/dev/null) + search_src_normalised=$(readlink -f "${search_src}" 2>/dev/null) + + # decide which path to use - normalised or original + local bind_src_compare="${bind_src_normalised:-${bind_src}}" + local search_src_compare="${search_src_normalised:-${search_src}}" + + [[ ${VERBOSE} -eq 1 ]] && echo "Comparing: '${bind_src_compare}' vs '${search_src_compare}'" + + if [[ "${bind_src_compare}" == "${search_src_compare}" ]]; then + return 0 # found target with same source (all good) + else + echo "${bind_src}" # return the conflicting source for error message + return 1 # found target with different source (conflict) + fi + fi + done + + return 2 # target not found in bind paths +} + # set defaults for command line arguments ACCESS="ro" CONTAINER="docker://ghcr.io/eessi/build-node:debian12" @@ -719,17 +787,38 @@ if [[ ! -z ${http_proxy} ]]; then HTTP_PROXY_IPV4=$(get_ipv4_address ${PROXY_HOST}) [[ ${VERBOSE} -eq 1 ]] && echo "HTTP_PROXY_IPV4='${HTTP_PROXY_IPV4}'" echo "CVMFS_HTTP_PROXY=\"${http_proxy}|http://${HTTP_PROXY_IPV4}:${PROXY_PORT}\"" \ - >> ${EESSI_TMPDIR}/repos_cfg/default.local + >> ${EESSI_TMPDIR}/repos_cfg/default.local [[ ${VERBOSE} -eq 1 ]] && echo "contents of default.local" [[ ${VERBOSE} -eq 1 ]] && cat ${EESSI_TMPDIR}/repos_cfg/default.local # if default.local is not BIND mounted into container, add it to BIND_PATHS src=${EESSI_TMPDIR}/repos_cfg/default.local target=/etc/cvmfs/default.local - if [[ ${BIND_PATHS} =~ "${target}" ]]; then - fatal_error "BIND target in '${src}:${target}' is already in paths to be bind mounted into the container ('${BIND_PATHS}')" ${REPOSITORY_ERROR_EXITCODE} - fi - BIND_PATHS="${BIND_PATHS},${src}:${target}" + + # check if target already exists in BIND_PATHS, and, if so, if sources are + # the same + conflict_src=$(check_bind_paths_for_target "${target}" "${src}" "${BIND_PATHS}") + check_result=$? + + case ${check_result} in + 0) + # target already bound with same source - no action needed + [[ ${VERBOSE} -eq 1 ]] && echo "Bind mount already configured: ${src}:${target}" + ;; + 1) + # target already bound with different source - conflict! + fatal_error "BIND target '${target}' conflict: already bound from '${conflict_src}', cannot bind from '${src}'" ${REPOSITORY_ERROR_EXITCODE} + ;; + 2) + # target not found - safe to add + if [[ -z ${BIND_PATH} ]]; then + BIND_PATHS="${src}:${target}" + else + BIND_PATHS="${BIND_PATHS},${src}:${target}" + fi + [[ ${VERBOSE} -eq 1 ]] && echo "Added bind mount: ${src}:${target}" + ;; + esac fi # 4. set up vars and dirs specific to a scenario From 1aa82b2cc60fa7b4671020e135c00ddae10c86e2 Mon Sep 17 00:00:00 2001 From: Thomas Roeblitz Date: Sat, 24 Jan 2026 20:37:42 +0100 Subject: [PATCH 2/2] remove trailing spaces --- eessi_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eessi_container.sh b/eessi_container.sh index 94777f98..411f600f 100755 --- a/eessi_container.sh +++ b/eessi_container.sh @@ -818,7 +818,7 @@ if [[ ! -z ${http_proxy} ]]; then fi [[ ${VERBOSE} -eq 1 ]] && echo "Added bind mount: ${src}:${target}" ;; - esac + esac fi # 4. set up vars and dirs specific to a scenario