MCPcopy Create free account
hub / github.com/buildpacks/pack / FilePathToURI

Function FilePathToURI

internal/paths/paths.go:31–51  ·  view source on GitHub ↗

FilePathToURI converts a filepath to URI. If relativeTo is provided not empty and path is a relative path it will be made absolute based on the provided value. Otherwise, the current working directory is used.

(path, relativeTo string)

Source from the content-addressed store, hash-verified

29// a relative path it will be made absolute based on the provided value. Otherwise, the
30// current working directory is used.
31func FilePathToURI(path, relativeTo string) (string, error) {
32 if IsURI(path) {
33 return path, nil
34 }
35
36 if !filepath.IsAbs(path) {
37 var err error
38 path, err = filepath.Abs(filepath.Join(relativeTo, path))
39 if err != nil {
40 return "", err
41 }
42 }
43
44 if runtime.GOOS == "windows" {
45 if strings.HasPrefix(path, `\\`) {
46 return "file://" + filepath.ToSlash(strings.TrimPrefix(path, `\\`)), nil
47 }
48 return "file:///" + filepath.ToSlash(path), nil
49 }
50 return "file://" + path, nil
51}
52
53// examples:
54//

Callers 11

testCreateBuilderFunction · 0.92
fetchLifecycleMethod · 0.92
uriFromLifecycleImageMethod · 0.92
testPackageBuildpackFunction · 0.92
testDownloaderFunction · 0.92
testBuildpackDownloaderFunction · 0.92
testMultiArchConfigFunction · 0.92
DownloadMethod · 0.92
testPathsFunction · 0.92

Calls 1

IsURIFunction · 0.85

Tested by 7

testCreateBuilderFunction · 0.74
testPackageBuildpackFunction · 0.74
testDownloaderFunction · 0.74
testBuildpackDownloaderFunction · 0.74
testMultiArchConfigFunction · 0.74
testPathsFunction · 0.74