ParseRelativePath parses a given directory path and returns the absolute path
(dir string)
| 260 | |
| 261 | // ParseRelativePath parses a given directory path and returns the absolute path |
| 262 | func ParseRelativePath(dir string) (string, error) { |
| 263 | // validate parameters |
| 264 | if dir == "" { |
| 265 | return "", ErrInvalidPath |
| 266 | } |
| 267 | |
| 268 | switch { |
| 269 | // if path is home, parse and set home dir |
| 270 | case dir[:2] == "~/": |
| 271 | home, err := getUserHomeDir() |
| 272 | if err != nil { |
| 273 | return "", err |
| 274 | } |
| 275 | return filepath.Join(home, dir[2:]), nil |
| 276 | // if the path starts with a dot, get the path relative to the current working directory |
| 277 | case strings.HasPrefix(dir, "."): |
| 278 | currentDir, err := getWorkingDir() |
| 279 | if err != nil { |
| 280 | return "", err |
| 281 | } |
| 282 | return filepath.Join(currentDir, dir), nil |
| 283 | default: |
| 284 | // otherwise, return the directory as is |
| 285 | return dir, nil |
| 286 | |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | // ValidateDirectory returns whether a directory exists and is empty |
| 291 | func ValidateDirectory(afs afero.Fs, dir string) error { |
no outgoing calls