From 8c7c2d0166c59754cd30e2e3ea6e21a3cb52762b Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Tue, 19 Apr 2022 17:42:47 -0700 Subject: handle correctly symlinks in parent directories Commit b9e2809fce57 introduced support for symlinks when specified in the config file for one of the binaries, but it breaks if there is a symlink in one of the parent directories. This patch fixes the behavior by doing the following: - get the absolute "real" path of the target file using realpath, not resolving symlinks for the parameter path (parents still get resolved) - get the absolute "real" path of the current directory using realpath This is necessary so that the two paths match in terms of symlinks resolution. - strip the base directory from the absolute path. The result is the target file with a path relative to the current directory without symlink resolution, but correctly handling the case where symlinks are presents in the parent directories. Signed-off-by: Stefano Stabellini Tested-by: Andrei Cherechesu --- scripts/uboot-script-gen | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen index c23caca..0adf523 100755 --- a/scripts/uboot-script-gen +++ b/scripts/uboot-script-gen @@ -211,7 +211,9 @@ function load_file() local filename=$1 local fit_scr_name=$2 - local relative_path="$(realpath --no-symlinks --relative-to=$PWD $filename)" + local absolute_path="$(realpath --no-symlinks $filename)" + local base="$(realpath $PWD)"/ + local relative_path=${absolute_path#"$base"} if test "$FIT" then -- cgit v1.2.3