diff options
author | Nicolas Lacasse <nlacasse@google.com> | 2019-02-01 15:22:22 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-02-01 15:23:43 -0800 |
commit | 92e85623a0cd7b2043a79b757e1874a67796dea9 (patch) | |
tree | 5a9883da502e64fd0726c62f2e3de2f2c9d87ef0 /runsc | |
parent | fe1369ac98a4f1d8af5e8be6da71165339e52034 (diff) |
Factor the subtargets method into a helper method with tests.
PiperOrigin-RevId: 232047515
Change-Id: I00f036816e320356219be7b2f2e6d5fe57583a60
Diffstat (limited to 'runsc')
-rw-r--r-- | runsc/boot/fs.go | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/runsc/boot/fs.go b/runsc/boot/fs.go index 5c5e650ca..ada292c9e 100644 --- a/runsc/boot/fs.go +++ b/runsc/boot/fs.go @@ -515,20 +515,10 @@ func addSubmountOverlay(ctx context.Context, inode *fs.Inode, submounts []string // subtargets takes a set of Mounts and returns only the targets that are // children of the given root. The returned paths are relative to the root. func subtargets(root string, mnts []specs.Mount) []string { - r := filepath.Clean(root) - if len(r) > 0 && r[len(r)-1] != '/' { - r += "/" - } var targets []string for _, mnt := range mnts { - t := filepath.Clean(mnt.Destination) - if strings.HasPrefix(t, r) { - // Make the mnt path relative to the root path. If the - // result is empty, then mnt IS the root mount, not a - // submount. We don't want to include those. - if t := strings.TrimPrefix(t, r); t != "" { - targets = append(targets, t) - } + if relPath, isSubpath := fs.IsSubpath(mnt.Destination, root); isSubpath { + targets = append(targets, relPath) } } return targets |