Download this file
| 1 | package hostbox |
| 2 | |
| 3 | import "path/filepath" |
| 4 | |
| 5 | func (p TypedParker) ParkedArtifactRoot(a Artifact) (string, error) { |
| 6 | root := p.ParkedRoots[a.Root] |
| 7 | if root == "" { |
| 8 | root = p.ParkedRoot |
| 9 | } |
| 10 | if root == "" { |
| 11 | return "", ErrTypedInventory |
| 12 | } |
| 13 | source := p.Roots[a.Root] |
| 14 | mount := a.Identity.MountPoint |
| 15 | if !p.CapturePersistent || root != source || mount == "" { |
| 16 | return root, nil |
| 17 | } |
| 18 | if !filepath.IsAbs(mount) || filepath.Clean(mount) != mount { |
| 19 | return "", ErrTypedInventory |
| 20 | } |
| 21 | rel, err := filepath.Rel(source, mount) |
| 22 | if err != nil { |
| 23 | return "", ErrTypedInventory |
| 24 | } |
| 25 | if managedName(rel) { |
| 26 | inside, err := filepath.Rel(mount, filepath.Join(source, a.Name)) |
| 27 | if err != nil || !managedName(inside) { |
| 28 | return "", ErrTypedInventory |
| 29 | } |
| 30 | return mount, nil |
| 31 | } |
| 32 | ancestor, err := filepath.Rel(mount, source) |
| 33 | if err != nil || (ancestor != "." && !managedName(ancestor)) { |
| 34 | return "", ErrTypedInventory |
| 35 | } |
| 36 | return root, nil |
| 37 | } |
| 38 | |