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)
| 72 | // treated as absolute, and the returned path will also always be absolute. In |
| 73 | // addition, the paths are cleaned before stripping the root. |
| 74 | func 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 |
searching dependent graphs…