copy-firmware: Fix linking directories when using compression
PATCH 1/1 copy-firmware: Fix linking directories when using compression
When copy-firmware is called with --xz or --zstd it will create broken symlinks for directories:
``` $ ./copy-firmware -v --zstd $dir [...] creating link qcom/LENOVO/21BX.zst -> ../sc8280xp/LENOVO/21BX.zst ```
The original target ../sc8280xp/LENOVO/21BX is a directory. Adding the compression extension to the directory name breaks the link. The directory qcom/sc8280xp/LENOVO/21BX exists but qcom/sc8280xp/LENOVO/21BX.zst does not exist.
The relative symlink needs to be resolved. If it points to a directory, create the symlink without the compression extension.
Signature · 2 lines
Benjamin Drung Debian & Ubuntu Developer
From 374ed7f228fc739e9b8393a17aae71b270a51217 Mon Sep 17 00:00:00 2001
From: Benjamin Drung <[email protected]>
Date: Tue, 18 Jul 2023 20:23:40 +0200
Subject: [PATCH] copy-firmware: Fix linking directories when using compression
When copy-firmware is called with --xz or --zstd it will create broken symlinks for directories:
``` $ ./copy-firmware -v --zstd $dir [...] creating link qcom/LENOVO/21BX.zst -> ../sc8280xp/LENOVO/21BX.zst ```
The original target ../sc8280xp/LENOVO/21BX is a directory. Adding the compression extension to the directory name breaks the link. The directory qcom/sc8280xp/LENOVO/21BX exists but qcom/sc8280xp/LENOVO/21BX.zst does not exist.
The relative symlink needs to be resolved. If it points to a directory, create the symlink without the compression extension.
--- copy-firmware.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
copy-firmware.sh +10 -3
@@ -94,9 +94,16 @@ grep -E '^Link:' WHENCE | sed -e 's/^Link: *//g;s/-> //g' | while read f d; do $verbose "WARNING: missing target for symlink $f" fi else - install -d "$destdir/$(dirname "$f")" - $verbose "creating link $f$compext -> $d$compext" - ln -s "$d$compext" "$destdir/$f$compext" + directory="$destdir/$(dirname "$f")" + install -d "$directory" + target="$(cd "$directory" && realpath -m -s "$d")" + if test -d "$target"; then + $verbose "creating link $f -> $d" + ln -s "$d" "$destdir/$f" + else + $verbose "creating link $f$compext -> $d$compext" + ln -s "$d$compext" "$destdir/$f$compext" + fi fi done
Signature · 1 line
2.39.2
Applied and pushed out.
josh
Quoted 21 lines · Benjamin Drung
When
copy-firmwareis called with--xzor--zstdit will create broken symlinks for directories:``` $ ./copy-firmware -v --zstd $dir [...] creating link qcom/LENOVO/21BX.zst -> ../sc8280xp/LENOVO/21BX.zst ```The original target
../sc8280xp/LENOVO/21BXis a directory. Adding the compression extension to the directory name breaks the link. The directoryqcom/sc8280xp/LENOVO/21BXexists butqcom/sc8280xp/LENOVO/21BX.zstdoes not exist.The relative symlink needs to be resolved. If it points to a directory, create the symlink without the compression extension.
--
Benjamin Drung
Debian & Ubuntu Developer