MCPcopy Create free account
hub / github.com/SolarLune/masterplan / PathToAbsolute

Method PathToAbsolute

project.go:1682–1706  ·  view source on GitHub ↗
(fp string, directory bool)

Source from the content-addressed store, hash-verified

1680}
1681
1682func (project *Project) PathToAbsolute(fp string, directory bool) string {
1683
1684 if filepath.IsAbs(fp) || strings.TrimSpace(fp) == "" {
1685 return fp
1686 }
1687 elements := []string{filepath.Dir(project.Filepath), filepath.FromSlash(string(fp))}
1688 final := filepath.Clean(filepath.Join(elements...))
1689
1690 var exists bool
1691 if directory {
1692 exists = FolderExists(final)
1693 } else {
1694 exists = FileExists(final)
1695 }
1696
1697 // if !exists {
1698 // elements = []string{filepath.Dir(LocalRelativePath("")), filepath.FromSlash(string(fp))} // TODO: REMOVE THIS AT SOME POINT IN THE FUTURE, AS THIS SERVES TO FIX A TEMPORARY BLUNDER CAUSED BY MAKING PATHS RELATIVE TO THE MASTERPLAN FOLDER
1699 // final = filepath.Clean(filepath.Join(elements...))
1700 // }
1701 // If the file doesn't exist, we'll just abandon our efforts; maybe it's a URL, for example.
1702 if !exists {
1703 return fp
1704 }
1705 return final
1706}

Callers 5

SaveMethod · 0.95
OpenProjectFromFunction · 0.95
NewSoundContentsFunction · 0.80
NewImageContentsFunction · 0.80
NewLinkContentsFunction · 0.80

Calls 2

FolderExistsFunction · 0.85
FileExistsFunction · 0.85

Tested by

no test coverage detected