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>
This commit is contained in:
Benjamin Drung 2023-07-18 20:23:40 +02:00 committed by Josh Boyer
parent 0a51959c6f
commit b6ea35ff6b
No known key found for this signature in database
GPG Key ID: A31B6BD72486CFD6
1 changed files with 10 additions and 3 deletions

View File

@ -94,10 +94,17 @@ 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")"
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
exit 0