Skip to content

Commit 81e2fd6

Browse files
committed
bugfix for #68
1 parent 723c651 commit 81e2fd6

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

rmate

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ function dirpath {
126126
(cd "$(dirname "$1")" >/dev/null 2>/dev/null || { echo "unable to cd to $1 directory" 1>&2; exit; } ; pwd -P)
127127
}
128128

129+
function resolvepath {
130+
local filepath="$1"
131+
local directory
132+
133+
while [ -L "$filepath" ]; do
134+
directory="$(cd -P "$(dirname "$filepath")" && pwd)"
135+
filepath="$(readlink "$filepath")"
136+
137+
if [[ "${filepath:0:1}" != "/" ]]; then
138+
filepath="$directory/$filepath"
139+
fi
140+
done
141+
142+
echo "$filepath"
143+
}
144+
129145
function canonicalize {
130146
local filepath="$1"
131147
local relativepath
@@ -136,9 +152,9 @@ function canonicalize {
136152
fi
137153

138154
local dir=$(dirpath "$filepath")
139-
155+
140156
if [ -L "$filepath" ]; then
141-
relativepath=$(cd "$dir" || { echo "unable to cd to $dir" 1>&2; exit; } ; readlink "$(basename "$filepath")")
157+
relativepath=$(cd "$dir" || { echo "unable to cd to $dir" 1>&2; exit; } ; resolvepath "$(basename "$filepath")")
142158
result=$(dirpath "$relativepath")/$(basename "$relativepath")
143159
else
144160
result=$(basename "$filepath")
@@ -148,7 +164,7 @@ function canonicalize {
148164
result="$dir/$result"
149165
fi
150166
fi
151-
167+
152168
echo "$result"
153169
}
154170

0 commit comments

Comments
 (0)