MCPcopy
hub / github.com/hashicorp/go-getter / SourceDirSubdir

Function SourceDirSubdir

source.go:17–51  ·  view source on GitHub ↗

SourceDirSubdir takes a source URL and returns a tuple of the URL without the subdir and the subdir. ex: dom.com/path/?q=p => dom.com/path/?q=p, "" proto://dom.com/path//*?q=p => proto://dom.com/path?q=p, "*" proto://dom.com/path//path2?q=p => proto://dom.com/path?q=p, "path2"

(src string)

Source from the content-addressed store, hash-verified

15// proto://dom.com/path//path2?q=p => proto://dom.com/path?q=p, "path2"
16//
17func SourceDirSubdir(src string) (string, string) {
18
19 // URL might contains another url in query parameters
20 stop := len(src)
21 if idx := strings.Index(src, "?"); idx > -1 {
22 stop = idx
23 }
24
25 // Calculate an offset to avoid accidentally marking the scheme
26 // as the dir.
27 var offset int
28 if idx := strings.Index(src[:stop], "://"); idx > -1 {
29 offset = idx + 3
30 }
31
32 // First see if we even have an explicit subdir
33 idx := strings.Index(src[offset:stop], "//")
34 if idx == -1 {
35 return src, ""
36 }
37
38 idx += offset
39 subdir := src[idx+2:]
40 src = src[:idx]
41
42 // Next, check if we have query parameters and push them onto the
43 // URL.
44 if idx = strings.Index(subdir, "?"); idx > -1 {
45 query := subdir[idx:]
46 subdir = subdir[:idx]
47 src += query
48 }
49
50 return src, subdir
51}
52
53// SubdirGlob returns the actual subdir with globbing processed.
54//

Callers 5

DetectFunction · 0.85
testModuleURLFunction · 0.85
GetMethod · 0.85
TestSourceDirSubdirFunction · 0.85
getXTerraformSourceMethod · 0.85

Calls

no outgoing calls

Tested by 2

testModuleURLFunction · 0.68
TestSourceDirSubdirFunction · 0.68