MCPcopy
hub / github.com/git-lfs/git-lfs / CanonicalizePath

Function CanonicalizePath

tools/filetools.go:493–510  ·  view source on GitHub ↗

CanonicalizePath takes a path and produces a canonical absolute path, performing any OS- or environment-specific path transformations (within the limitations of the Go standard library). If the path is empty, it returns the empty path with no error. If missingOk is true, then if the canonicalized

(path string, missingOk bool)

Source from the content-addressed store, hash-verified

491// the empty path with no error. If missingOk is true, then if the
492// canonicalized path does not exist, an absolute path is given instead.
493func CanonicalizePath(path string, missingOk bool) (string, error) {
494 path, err := TranslateCygwinPath(path)
495 if err != nil {
496 return "", err
497 }
498 if len(path) > 0 {
499 path, err := filepath.Abs(path)
500 if err != nil {
501 return "", err
502 }
503 result, err := CanonicalizeSystemPath(path)
504 if err != nil && os.IsNotExist(err) && missingOk {
505 return path, nil
506 }
507 return result, err
508 }
509 return "", nil
510}
511
512const (
513 windowsPrefix = `.\`

Callers 6

canonicalizeEnvironmentFunction · 0.92
GitAndRootDirsFunction · 0.92
RootDirFunction · 0.92
GitDirFunction · 0.92
GitCommonDirFunction · 0.92
TestWorktreesFunction · 0.92

Calls 2

TranslateCygwinPathFunction · 0.85
CanonicalizeSystemPathFunction · 0.70

Tested by 1

TestWorktreesFunction · 0.74