add 159 to patch

This commit is contained in:
Tobias Powalowski 2022-12-02 12:31:26 +01:00
parent 194f8fd63e
commit 945f87f74d

View file

@ -583,30 +583,44 @@ add_symlink() {
# Add a symlink to the initcpio image. There is no checking done # Add a symlink to the initcpio image. There is no checking done
# to ensure that the target of the symlink exists. # to ensure that the target of the symlink exists.
# $1: pathname of symlink on image # $1: pathname of symlink on image
# $2: absolute path to target of symlink (optional, can be read from $1) # $2: path to target of symlink (optional, can be read from $1)
local name=$1 target=$2 local name="$1" target="${2:-$1}" linkobject
(( $# == 1 || $# == 2 )) || return 1 (( $# == 1 || $# == 2 )) || return 1
if [[ -z "$target" || "$name" == "$target" ]]; then if [[ "$name" == "$target" && -L "$target" ]]; then
target="$(find "$name" -prune -printf '%l')" linkobject="$(find "$name" -prune -printf '%l')"
elif [[ -L "$target" ]]; then # if the link name and target are the same, treat it as if no target is specified
target="$(realpath -eq -- "$target")" target=''
fi fi
if [[ -z "$target" ]]; then
if [[ -z "${target:-$linkobject}" ]]; then
error 'invalid symlink: %s' "$name" error 'invalid symlink: %s' "$name"
return 1 return 1
fi fi
add_dir "${name%/*}" [[ -d "${BUILDROOT}/${name%/*}" ]] || add_dir "${name%/*}"
if [[ -L $BUILDROOT$1 ]]; then if [[ -L "${BUILDROOT}/${name}" ]]; then
quiet "overwriting symlink %s -> %s" "$name" "$target" quiet "overwriting symlink %s -> %s" "$name" "${target:-$linkobject}"
else else
quiet "adding symlink: %s -> %s" "$name" "$target" quiet "adding symlink: %s -> %s" "$name" "${target:-$linkobject}"
fi
if [[ -n "$linkobject" ]]; then
# copy the symlink to preserve relativity
cp -dT -- "$name" "${BUILDROOT}/${name}"
# Add nested symlinks
if [[ "${linkobject:0:1}" == '/' && -L "$linkobject" ]]; then
add_symlink "$linkobject"
elif [[ "${linkobject:0:1}" != '/' && -L "${name%/*}/${linkobject}" ]]; then
add_symlink "${name%/*}/${linkobject}"
fi
else
# create the symlink
ln -sfn "$target" "${BUILDROOT}/${name}"
fi fi
ln -sfn "$target" "$BUILDROOT$name"
} }
add_file() { add_file() {