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

Function LexicallyStripRoot

internal/pathrs/path.go:74–86  ·  view source on GitHub ↗

LexicallyStripRoot returns the passed path, stripping the root path if it was (lexicially) inside it. Note that both passed paths will always be treated as absolute, and the returned path will also always be absolute. In addition, the paths are cleaned before stripping the root.

(root, path string)

Source from the content-addressed store, hash-verified

72// treated as absolute, and the returned path will also always be absolute. In
73// addition, the paths are cleaned before stripping the root.
74func LexicallyStripRoot(root, path string) string {
75 // Make the paths clean and absolute.
76 root, path = LexicallyCleanPath("/"+root), LexicallyCleanPath("/"+path)
77 switch {
78 case path == root:
79 path = "/"
80 case root == "/":
81 // do nothing
82 default:
83 path = strings.TrimPrefix(path, root+"/")
84 }
85 return LexicallyCleanPath("/" + path)
86}
87
88// hallucinateUnsafePath creates a new unsafePath which has all symlinks
89// (including dangling symlinks) fully resolved and any non-existent components

Callers 4

createOpenMountpointMethod · 0.92
reopenAfterMountFunction · 0.92
hallucinateUnsafePathFunction · 0.85
TestLexicallyStripRootFunction · 0.85

Calls 1

LexicallyCleanPathFunction · 0.85

Tested by 1

TestLexicallyStripRootFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…