@@ -118,6 +118,7 @@ func HasPathSeperatorSuffix(ppath string) bool {
118
118
}
119
119
120
120
var pathSeperatorRegex = regexp .MustCompile (`(\\|/)` )
121
+ var winPathSeperatorRegex = regexp .MustCompile (`[\\]+` )
121
122
122
123
func GetPathSeperator (ppath string ) string {
123
124
matches := pathSeperatorRegex .FindAllStringSubmatch (ppath , 1 )
@@ -127,6 +128,53 @@ func GetPathSeperator(ppath string) string {
127
128
return ``
128
129
}
129
130
131
+ func RealPath (fullPath string ) string {
132
+ if len (fullPath ) == 0 {
133
+ return fullPath
134
+ }
135
+ var root string
136
+ var pathSeperator string
137
+ if strings .HasPrefix (fullPath , `/` ) {
138
+ pathSeperator = `/`
139
+ } else {
140
+ pathSeperator = GetPathSeperator (fullPath )
141
+ if pathSeperator == `/` {
142
+ fullPath = `/` + fullPath
143
+ } else {
144
+ cleanedFullPath := winPathSeperatorRegex .ReplaceAllString (fullPath , `\` )
145
+ parts := strings .SplitN (cleanedFullPath , `\` , 2 )
146
+ if ! strings .HasSuffix (parts [0 ], `:` ) {
147
+ if len (parts [0 ]) > 0 {
148
+ parts [0 ] = `c:\` + parts [0 ]
149
+ } else {
150
+ parts [0 ] = `c:`
151
+ }
152
+ }
153
+ root = parts [0 ] + `\`
154
+ if len (parts ) != 2 {
155
+ return fullPath
156
+ }
157
+ fullPath = parts [1 ]
158
+ }
159
+ }
160
+ parts := pathSeperatorRegex .Split (fullPath , - 1 )
161
+ result := make ([]string , 0 , len (parts ))
162
+ for _ , part := range parts {
163
+ if part == `.` {
164
+ continue
165
+ }
166
+ if part == `..` {
167
+ if len (result ) <= 1 {
168
+ continue
169
+ }
170
+ result = result [0 : len (result )- 1 ]
171
+ continue
172
+ }
173
+ result = append (result , part )
174
+ }
175
+ return root + strings .Join (result , pathSeperator )
176
+ }
177
+
130
178
func SplitFileDirAndName (ppath string ) (dir string , name string ) {
131
179
if len (ppath ) == 0 {
132
180
return
0 commit comments