From 865ebc9e0c433ca00dcdc97dfb5721b8475aa0e9 Mon Sep 17 00:00:00 2001 From: Hao Wu Date: Tue, 26 May 2026 02:21:52 +0000 Subject: [PATCH] Fix greenplum_path.sh GPHOME resolution under relative symlinks When GPHOME is reached via a symlink whose target is stored as a relative path (e.g. /opt/database -> database-2.1.0), the previous logic ran a bare `readlink` on the script's directory and accepted the link target verbatim. `readlink` returns the symlink's target string as-is; for a relative target this leaves GPHOME as a relative path, so PYTHONPATH becomes `database-2.1.0/lib/python` and gpstart fails with ModuleNotFoundError: No module named 'gppylib' the moment the shell's cwd is anything other than the symlink's parent. Replace the symlink-vs-not branch with a single `pwd -P`, which resolves every symlink component and returns the canonical absolute path regardless of how the user reached the directory. This also removes the unnecessary `[ -L ... ]` test and the dependency on GNU readlink semantics. --- gpMgmt/bin/generate-cloudberry-env.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gpMgmt/bin/generate-cloudberry-env.sh b/gpMgmt/bin/generate-cloudberry-env.sh index 7f1f9074efc..0eca71b4884 100755 --- a/gpMgmt/bin/generate-cloudberry-env.sh +++ b/gpMgmt/bin/generate-cloudberry-env.sh @@ -17,13 +17,15 @@ fi if test -z "$SCRIPT_PATH"; then echo "The shell cannot be identified. \$GPHOME may not be set correctly." >&2 fi -SCRIPT_DIR="$(cd "$(dirname "${SCRIPT_PATH}")" >/dev/null 2>&1 && pwd)" -if [ ! -L "${SCRIPT_DIR}" ]; then - GPHOME=${SCRIPT_DIR} -else - GPHOME=$(readlink "${SCRIPT_DIR}") -fi +# downstream PATH / PYTHONPATH / LD_LIBRARY_PATH derivations stay valid +# even when GPHOME is reached via a symlink whose target is a relative +# path (e.g. /opt/database -> database-2.1.0). `pwd -P` resolves every +# symlink component, returning the physical absolute path. This replaces +# an earlier branch that ran bare `readlink` on the script's directory, +# which would return the symlink target verbatim and break with relative +# targets (PYTHONPATH became relative, gppylib import failed). +GPHOME="$(cd "$(dirname "${SCRIPT_PATH}")" >/dev/null 2>&1 && pwd -P)" EOF cat <<"EOF"