Skip to content

fix: relative symlink resolution in install script#1244

Draft
V-Subhankar-infy wants to merge 1 commit into
devcontainers:mainfrom
V-Subhankar-infy:main
Draft

fix: relative symlink resolution in install script#1244
V-Subhankar-infy wants to merge 1 commit into
devcontainers:mainfrom
V-Subhankar-infy:main

Conversation

@V-Subhankar-infy

Copy link
Copy Markdown
Member

Summary

This PR fixes relative symlink resolution in the install script for split local install layouts, such as a symlinked launcher in ~/.local/bin and the CLI payload in ~/.local/lib/devcontainers. With this change, devcontainer resolves paths correctly regardless of the caller’s current working directory.

Fixes #1232

Issue Context

Issue #1232 describes a failure in this setup:

  1. Install the CLI under ~/.local/lib/devcontainers
  2. Create a relative symlink at ~/.local/bin/devcontainer that points to ../lib/devcontainers/bin/devcontainer
  3. Run devcontainer from a directory other than ~/.local/bin

Observed error:

/home/<user>/.local/bin/devcontainer: line 18: cd: ../lib/devcontainers/bin: No such file or directory

Root Cause

The wrapper could resolve a relative symlink target before canonicalizing the path. As a result, later path derivation could depend on the current working directory, which caused failures in split local install layouts.

Reproduction (Compact)

INSTALL_DIR="$HOME/.local"
mkdir -p "$INSTALL_DIR/bin"
curl -sSLO https://raw.githubusercontent.com/devcontainers/cli/main/scripts/install.sh
chmod +x install.sh
./install.sh --prefix "${INSTALL_DIR}/lib/devcontainers"
ln -s ../lib/devcontainers/bin/devcontainer "${INSTALL_DIR}/bin/devcontainer"
export PATH="${INSTALL_DIR}/bin:$PATH"
cd "$HOME"
devcontainer --version

Fix (Single-Line Change)

-SCRIPT_PATH="$(readlink "$0" 2>/dev/null || readlink -f "$0" 2>/dev/null || echo "$0")"
+SCRIPT_PATH="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"

Why This Fix Works

By preferring canonical resolution first, the wrapper gets an absolute and normalized script path whenever possible. This makes installation path derivation independent of the caller’s working directory, so relative symlink launches resolve correctly.

Validation

A regression test verifies that:

  1. A relative symlink to the wrapper works from a different directory
  2. Execution succeeds with exit code 0
  3. The reported version matches the installed CLI version

Scope and Risk

  • Scope is minimal: one functional line in symlink resolution logic
  • Risk is low: direct execution and already-canonical paths are unchanged
  • Outcome: split local install workflows now behave correctly and consistently

@V-Subhankar-infy V-Subhankar-infy changed the title Fix relative symlink resolution in install script fix: relative symlink resolution in install script Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

install.sh wrapper relative link not resolved correctly

1 participant