strip_c_comments_safe.sh: add processing of direct (non-chained) symlinks
This commit is contained in:
1 parent
98744b340b
commit
9a9d547b84
1 file changed
+20
-4
@@ -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)
|
||||
Reference in new issue
Block a user