MCPcopy
hub / github.com/opencontainers/runc / IsLexicallyInRoot

Function IsLexicallyInRoot

internal/pathrs/path.go:34–38  ·  view source on GitHub ↗

IsLexicallyInRoot is shorthand for strings.HasPrefix(path+"/", root+"/"), but properly handling the case where path or root have a "/" suffix. NOTE: The return value only make sense if the path is already mostly cleaned (i.e., doesn't contain "..", ".", nor unneeded "/"s).

(root, path string)

Source from the content-addressed store, hash-verified

32// NOTE: The return value only make sense if the path is already mostly cleaned
33// (i.e., doesn't contain "..", ".", nor unneeded "/"s).
34func IsLexicallyInRoot(root, path string) bool {
35 root = strings.TrimRight(root, "/")
36 path = strings.TrimRight(path, "/")
37 return strings.HasPrefix(path+"/", root+"/")
38}
39
40// LexicallyCleanPath makes a path safe for use with filepath.Join. This is
41// done by not only cleaning the path, but also (if the path is relative)

Callers 4

createOpenMountpointMethod · 0.92
mountToRootfsFunction · 0.92
reopenAfterMountFunction · 0.92
TestIsLexicallyInRootFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestIsLexicallyInRootFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…