Skip to content

Commit

Permalink
realpath: handle relative symlinks with . and ..
Browse files Browse the repository at this point in the history
  • Loading branch information
nkraetzschmar committed Jun 17, 2024
1 parent 47a8678 commit 5eb999b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/realpath
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ realpath() (
[ "$max_depth" -gt 0 ]
dirname="$(realpath "$(dirname "$file")" "$(( max_depth - 1 ))" | sed 's|/$||')"
basename="$(basename "$file")"
file="$dirname/$basename"
if [ "$basename" = . ]; then
file="$dirname"
elif [ "$basename" = .. ]; then
file="$(dirname "$dirname")"
else
file="$dirname/$basename"
fi
if [ -L "$root$file" ]; then
target="$(readlink "$root$file")"
if [[ "$target" = /* ]]; then
Expand Down

0 comments on commit 5eb999b

Please sign in to comment.