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

Method PathToRelative

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

Source from the content-addressed store, hash-verified

1659}
1660
1661func (project *Project) PathToRelative(fp string, directory bool) string {
1662
1663 var exists bool
1664 if directory {
1665 exists = FolderExists(fp)
1666 } else {
1667 exists = FileExists(fp)
1668 }
1669
1670 if !filepath.IsAbs(fp) || strings.TrimSpace(fp) == "" || !exists {
1671 return fp
1672 }
1673 rel, err := filepath.Rel(filepath.Dir(project.Filepath), string(fp))
1674 // We don't do anything if the path could not be made relative; a possibility is that it's not possible (on Windows, for example, there is no way to get
1675 // a relative path from C:\ to D:\. They're two different drives. There is no relative path that works here.)
1676 if err != nil {
1677 return fp
1678 }
1679 return filepath.ToSlash(rel)
1680}
1681
1682func (project *Project) PathToAbsolute(fp string, directory bool) string {
1683

Callers 1

SaveMethod · 0.95

Calls 2

FolderExistsFunction · 0.85
FileExistsFunction · 0.85

Tested by

no test coverage detected