diff options
author | Benjamin Drung <benjamin.drung@canonical.com> | 2023-07-18 20:23:40 +0200 |
---|---|---|
committer | Josh Boyer <jwboyer@kernel.org> | 2023-07-25 06:53:30 -0400 |
commit | b6ea35ff6b9869470a0c68813f1668acb3d356a8 (patch) | |
tree | 4005837d2eb5418dbe5a871e3c9529ed45482677 | |
parent | 0a51959c6fd4248b454f7250997fd4f13500fb8a (diff) | |
download | linux-firmware-b6ea35ff6b9869470a0c68813f1668acb3d356a8.tar.gz |
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.
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
Signed-off-by: Josh Boyer <jwboyer@kernel.org>
-rwxr-xr-x | copy-firmware.sh | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/copy-firmware.sh b/copy-firmware.sh index a6be8c74..148f0f19 100755 --- a/copy-firmware.sh +++ b/copy-firmware.sh @@ -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 |