[pacman-dev] [PATCH] meson: make our symlinking script more portable

Allan McRae allan at archlinux.org
Mon Apr 19 07:42:24 UTC 2021


On 18/4/21 12:42 pm, Eli Schwartz wrote:
> We do not need the --relative case as it is dead code (we only ever link
> a filename without directory components).
> 
> For the rest, GNU-specific ln -T does two things:
> 
> - if the link name is an existing directory, ln fails instead of
>   creating a surprising link inside the directory
> - if the link name is a symlink to a directory, ln treats it as a file,
>   and due to -f, unlinks it
> 
> The second case can be portably solved by ln -n, and the first case is
> not actually currently functional, but we can portably replace the error
> message with rmdir, so, why not?

Can we?  That assumes the directory is non-empty and rmdir fails.  I
don't think removing an empty directory and replacing it with a symlink
is expected behaviour.

Can we just abort with an error if the target is a directory?

Allan

> 
> Signed-off-by: Eli Schwartz <eschwartz at archlinux.org>
> ---
>  build-aux/meson-make-symlink.sh | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/build-aux/meson-make-symlink.sh b/build-aux/meson-make-symlink.sh
> index 501cd43d4..27d068efe 100644
> --- a/build-aux/meson-make-symlink.sh
> +++ b/build-aux/meson-make-symlink.sh
> @@ -5,8 +5,11 @@ set -eu
>  # and we need to create the target directory...
>  
>  mkdir -vp "$(dirname "${DESTDIR:-}$2")"
> -if [ "$(dirname $1)" = . ]; then
> -        ln -vfs -T "$1" "${DESTDIR:-}$2"
> -else
> -        ln -vfs -T --relative "${DESTDIR:-}$1" "${DESTDIR:-}$2"
> +
> +# ln -T is neither portable, nor useful if we would like to actually succeed
> +# ln -F is nice, but BSD only
> +if [ ! -L "${DESTDIR:-}$2" ] && [ -d "${DESTDIR:-}$2" ]; then
> +	rmdir "${DESTDIR:-}$2"
>  fi
> +
> +ln -vnfs "$1" "${DESTDIR:-}$2"
> 


More information about the pacman-dev mailing list