fix: relative symlink resolution in install script#1244
Open
V-Subhankar-infy wants to merge 3 commits into
Open
fix: relative symlink resolution in install script#1244V-Subhankar-infy wants to merge 3 commits into
V-Subhankar-infy wants to merge 3 commits into
Conversation
|
Beware that --- a/devcontainer 2026-06-19 15:12:58
+++ b/devcontainer 2026-06-19 15:13:11
@@ -6,15 +6,22 @@
# Resolve the installation directory
# Handle both direct execution and symlinked scenarios
-if [ -L "$0" ]; then
- # Follow symlink
- SCRIPT_PATH="$(readlink "$0" 2>/dev/null || readlink -f "$0" 2>/dev/null || echo "$0")"
-else
- SCRIPT_PATH="$0"
-fi
-
-# Get absolute path to script directory
-SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_PATH")" && pwd)"
+SCRIPT_DIR="$(
+ CDPATH=
+ self=$0
+
+ while [ -L "$self" ]; do
+ cd -- "${self%/*}" >/dev/null || :
+ self=$(readlink "${self##*/}")
+ done
+
+ case "$self" in
+ (*/*) ;;
+ (*) self=./$self ;;
+ esac
+
+ cd -P -- "${self%/*}" >/dev/null && pwd
+)"
INSTALL_DIR="$(dirname "$SCRIPT_DIR")"
# Paths to bundled components(Reference/explanation: https://stackoverflow.com/a/246128/1968) |
d34e588 to
e612da1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes relative symlink resolution in the install script for split local layouts (e.g. a launcher in
~/.local/binpointing to a payload in~/.local/lib/devcontainers). The wrapper now resolves its own location with portable POSIX shell built-ins instead of GNU-specificreadlink -f, sodevcontainerworks regardless of the caller's working directory and shell environment (Linux, macOS, BSD).Fixes #1232
Root Cause
A single
readlinkcall pluscd "$(dirname ...)" && pwdresolved relative symlink targets against the caller's CWD rather than the link's own directory, and thereadlink -ffallback isn't portable to macOS/BSD.Reproduction of error
Fix
The script-location resolver now walks the symlink chain one hop at a time,
cd-ing into each link's directory before reading the next target, then canonicalizes the final directory. This replaces the previous singlereadlinkresolution.Why It Works
cd -P … && pwdfor an absolute, canonical path.readlink,${var%/*},cd -P,pwd) — noreadlink -f/realpath.CDPATH=cleared; no leakedcdor stray output.Validation
Regression test confirms a relative symlink launched from another directory exits
0and reports the installed CLI version.Scope & Risk
One resolution block; no install/download changes. Direct execution and absolute symlinks are unchanged. Low risk, plus improved cross-platform portability.
Credits
Thanks to @klmr for the portable POSIX symlink-resolution approach.