File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff 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+
129145function 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
You can’t perform that action at this time.
0 commit comments