relativeToWorkdir returns file relative to the current working directory when possible, otherwise it returns file unchanged.
(file string)
| 163 | // relativeToWorkdir returns file relative to the current working directory when |
| 164 | // possible, otherwise it returns file unchanged. |
| 165 | func relativeToWorkdir(file string) string { |
| 166 | wd, err := os.Getwd() |
| 167 | if err != nil { |
| 168 | return file |
| 169 | } |
| 170 | wd, err = filepath.Abs(wd) |
| 171 | if err != nil { |
| 172 | return file |
| 173 | } |
| 174 | rel, err := filepath.Rel(wd, file) |
| 175 | if err != nil { |
| 176 | return file |
| 177 | } |
| 178 | return rel |
| 179 | } |
no outgoing calls