MCPcopy Create free account
hub / github.com/activecm/rita / ParseRelativePath

Function ParseRelativePath

util/util.go:262–288  ·  view source on GitHub ↗

ParseRelativePath parses a given directory path and returns the absolute path

(dir string)

Source from the content-addressed store, hash-verified

260
261// ParseRelativePath parses a given directory path and returns the absolute path
262func 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
291func ValidateDirectory(afs afero.Fs, dir string) error {

Callers 6

importValidMIMETypesMethod · 0.92
getCustomFeedsListFunction · 0.92
RunImportCmdFunction · 0.92
ValidateLogDirectoryFunction · 0.92
ValidateConfigPathFunction · 0.92
TestParseRelativePathFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseRelativePathFunction · 0.68