Skip to content

#276 portable readlink -f via abspath function - #276

Open
VasilevNStas wants to merge 1 commit into
zerocracy:masterfrom
VasilevNStas:276-readlink-portable
Open

#276 portable readlink -f via abspath function#276
VasilevNStas wants to merge 1 commit into
zerocracy:masterfrom
VasilevNStas:276-readlink-portable

Conversation

@VasilevNStas

Copy link
Copy Markdown
Contributor

readlink -f is a GNU coreutils extension not available on macOS by default. This makes local development on macOS impossible — entry.sh immediately fails with "readlink: illegal option -- f".

What this PR does

Replaces the single readlink -f call with a portable abspath() function:

abspath() {
  local target="$1"
  while [ -L "${target}" ]; do
    target=$(readlink "${target}")
  done
  cd "$(dirname "${target}")" 2>/dev/null && pwd -P
}
self=$(abspath "$0")
Feature Before After
Linux (production) readlink -f abspath()
macOS (dev) illegal option -- f ✅ works
Symlink resolution ✅ one level ✅ chain (while loop)
Return type absolute dir absolute dir

Why not realpath?

realpath from brew install coreutils would require an external dependency. The cd + pwd -P approach is pure bash/POSIX and works everywhere.

Existing test coverage

The existing test test_resolves_real_path_when_invoked_via_symlink validates exactly this behaviour — it creates a symlink to entry.sh, invokes it, and asserts the resolved paths point to the real project directories.

Checklist

  • bundle exec rubocop — 0 offences
  • bundle exec rake — all tasks pass
  • HoC ≤ 133

@yegor256 please review

@VasilevNStas
VasilevNStas requested a review from yegor256 as a code owner June 29, 2026 16:57
readlink -f is not available on macOS by default (only Linux/GNU coreutils).
This breaks local development on macOS for anyone testing entry.sh changes.

Replace it with a portable abspath function that:
- Resolves symlinks (same as readlink -f)
- Works on both Linux and macOS
- Uses only POSIX commands and basic bash (cd + pwd -P)

The while-loop handles chains of symlinks, making it equivalent
to readlink -f behaviour.

Note: entry.sh runs in Linux Docker containers in production, so
readlink -f worked there. This fix improves the developer experience
for macOS users without changing production behaviour.
@VasilevNStas
VasilevNStas force-pushed the 276-readlink-portable branch from b7c7c21 to d05e4ed Compare June 29, 2026 17:04
@VasilevNStas

Copy link
Copy Markdown
Contributor Author

@yegor256 — readlink -f is a GNU extension that doesn't exist on macOS. This means anyone developing on a Mac (including CI maintainers and contributors) gets an immediate error when testing entry.sh locally. The abspath() function replaces it with pure POSIX cd + pwd -P, preserving symlink resolution. The existing test test_resolves_real_path_when_invoked_via_symlink validates this behaviour. Low risk, high impact for developer experience.

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.

1 participant