From 9a9d547b84490a8112b750eca5857dd6bc6305ce Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Jul 2026 10:00:59 +0000 Subject: [PATCH] strip_c_comments_safe.sh: add processing of direct (non-chained) symlinks --- strip_c_comments_safe.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/strip_c_comments_safe.sh b/strip_c_comments_safe.sh index f1b5e5238..1ba667c24 100755 --- a/strip_c_comments_safe.sh +++ b/strip_c_comments_safe.sh @@ -108,6 +108,8 @@ if [[ ! -d "$TARGET_DIR" ]]; then exit 1 fi +TARGET_DIR=$(cd -- "$TARGET_DIR" && pwd) + process_file() { local mode="$1" local file="$2" @@ -432,8 +434,22 @@ if [[ "$WITH_CMAKE" -eq 1 ]]; then find_expr+=( -o -name "*.cmake" ) fi -find "$TARGET_DIR" -type f \( "${find_expr[@]}" \) -print0 | +declare -A seen_files=() + while IFS= read -r -d '' file; do - mode="$(detect_mode "$file")" - [[ -n "$mode" ]] && process_file "$mode" "$file" -done \ No newline at end of file + real_file="$file" + if [[ -L "$file" ]]; then + target=$(readlink "$file") + if [[ "$target" != /* ]]; then + dir="$(cd "$(dirname "$file")" && pwd -P)" || continue + target="$dir/$target" + fi + [[ -L "$target" ]] && continue + [[ ! -f "$target" ]] && continue + real_file="$target" + fi + [[ -n "${seen_files[$real_file]+x}" ]] && continue + seen_files[$real_file]=1 + mode="$(detect_mode "$real_file")" + [[ -n "$mode" ]] && process_file "$mode" "$real_file" +done < <(find "$TARGET_DIR" \( -type f -o -type l \) \( "${find_expr[@]}" \) -print0) \ No newline at end of file