MCPcopy Create free account
hub / github.com/containerd/nerdctl / pathOnHost

Method pathOnHost

pkg/containerutil/cp_resolve_linux.go:257–276  ·  view source on GitHub ↗

pathOnHost will return the *host* location of a container path, accounting for volumes. The provided path must be fully resolved, as returned by `resolvePath`.

(path string)

Source from the content-addressed store, hash-verified

255// pathOnHost will return the *host* location of a container path, accounting for volumes.
256// The provided path must be fully resolved, as returned by `resolvePath`.
257func (res *resolver) pathOnHost(path string) string {
258 hostRoot := res.hostRoot
259 path = filepath.Clean(path)
260 itemized := strings.Split(path, string(os.PathSeparator))
261
262 containerRoot := "/"
263 sub := itemized
264
265 for _, mnt := range res.mounts {
266 if candidateIsParent, subPath := isParent(itemized, strings.Split(mnt.Destination, string(os.PathSeparator))); candidateIsParent {
267 if len(mnt.Destination) > len(containerRoot) {
268 containerRoot = mnt.Destination
269 hostRoot = mnt.Source
270 sub = subPath
271 }
272 }
273 }
274
275 return filepath.Join(append([]string{hostRoot}, sub...)...)
276}
277
278// getMount returns the mount locator for a given fully-resolved path, along with the corresponding subpath of the path
279// relative to the locator

Callers 1

resolvePathMethod · 0.95

Calls 1

isParentFunction · 0.85

Tested by

no test coverage detected