MCPcopy
hub / github.com/docker/docker-agent / ExtraWorkspace

Function ExtraWorkspace

pkg/sandbox/args.go:23–54  ·  view source on GitHub ↗

ExtraWorkspace returns the directory to mount as a read-only extra workspace when the agent file lives outside the main workspace. The agent reference may be a path, an OCI/URL reference, a built-in name, or an alias defined in the user's config — ExtraWorkspace delegates resolution to [config.Reso

(wd, agentRef string)

Source from the content-addressed store, hash-verified

21// under wd), the reference cannot be resolved, or the resolved source
22// has no on-disk parent directory.
23func ExtraWorkspace(wd, agentRef string) string {
24 if agentRef == "" {
25 return ""
26 }
27
28 source, err := config.Resolve(agentRef, nil)
29 if err != nil {
30 return ""
31 }
32
33 parent := source.ParentDir()
34 if parent == "" {
35 return ""
36 }
37
38 absParent, err := filepath.Abs(parent)
39 if err != nil {
40 return ""
41 }
42 absWd, err := filepath.Abs(wd)
43 if err != nil {
44 return ""
45 }
46
47 // No extra mount needed if the file is already under the workspace.
48 rel, err := filepath.Rel(absWd, absParent)
49 if err == nil && rel != ".." && !startsWithParent(rel) {
50 return ""
51 }
52
53 return absParent
54}
55
56// startsWithParent reports whether rel begins with a "../" segment,
57// which means absParent is not a subdirectory of absWd.

Callers 2

TestExtraWorkspaceFunction · 0.92
runInSandboxFunction · 0.92

Calls 3

ResolveFunction · 0.92
startsWithParentFunction · 0.85
ParentDirMethod · 0.65

Tested by 1

TestExtraWorkspaceFunction · 0.74