From 5ba62584156074eb70181d38bd7294fd1c2e525d Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 11 Jan 2026 11:43:08 +0100 Subject: [PATCH] licenses: Verify validity of the symlink files (#46444) Release Notes: - N/A *or* Added/Fixed/Improved ... --- script/check-licenses | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/script/check-licenses b/script/check-licenses index 0363f31970f936e26c61f734bf88ed5f60dc0393..61db9c15d5218a84330526419050bd0e027c84c9 100755 --- a/script/check-licenses +++ b/script/check-licenses @@ -5,6 +5,31 @@ set -euo pipefail AGPL_CRATES=("collab") RELEASE_CRATES=("cli" "remote_server" "zed") +check_symlink_target () { + local symlink_path="$1" + local license_name="$2" + + local target=$(readlink "$symlink_path") + + local dir=$(dirname "$symlink_path") + local depth=$(echo "$dir" | tr '/' '\n' | wc -l) + local expected_prefix="" + for ((i = 0; i < depth; i++)); do + expected_prefix="../$expected_prefix" + done + local expected_target="${expected_prefix}${license_name}" + + if [[ "$target" != "$expected_target" ]]; then + echo "Error: $symlink_path points to '$target' but should point to '$expected_target'" + exit 1 + fi + + if [[ ! -e "$symlink_path" ]]; then + echo "Error: $symlink_path is a broken symlink (target '$target' does not exist)" + exit 1 + fi +} + check_license () { local dir="$1" local allowed_licenses=() @@ -25,6 +50,7 @@ check_license () { for license in "${allowed_licenses[@]}"; do if [[ -L "$dir/$license" ]]; then + check_symlink_target "$dir/$license" "$license" return 0 elif [[ -e "$dir/$license" ]]; then echo "Error: $dir/$license exists but is not a symlink."