Merge pull request #2 from IghuToh0/copilot/fuege-prozessierung-von-symlinks-ein

strip_c_comments_safe.sh: process direct symlinks to regular files
This commit is contained in:
Torsten Wierschin authored and GitHub committed 2026-07-14 12:02:02 +02:00
commit ad1f62c4ee
1 file changed
+20 -4
+20 -4
View File
@@ -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
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)