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

Eli Schwartz eschwartz at archlinux.org
Sun Apr 18 02:42:41 UTC 2021


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?

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"
-- 
2.31.1


More information about the pacman-dev mailing list