Skip to content

Commit

Permalink
Improve subpath to mount matching
Browse files Browse the repository at this point in the history
to fix an issue on GitHub Actions

Signed-off-by: Christian Dupuis <[email protected]>
  • Loading branch information
cdupuis committed Sep 24, 2024
1 parent 01de99b commit 17f3ee9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
12 changes: 6 additions & 6 deletions syft/internal/fileresolver/path_skipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ func (ps pathSkipper) pathIndexVisitor(_ string, givenPath string, _ os.FileInfo
for _, mi := range ps.mounts {
conditionalPaths, ignorable := ps.ignorableMountTypes[mi.FSType]

if len(conditionalPaths) == 0 {
// Rule 1: ignore any path within a mount point that is of the given filesystem type unconditionally
if !containsPath(givenPath, mi.Mountpoint) {
continue
}
if !containsPath(givenPath, mi.Mountpoint) {
continue
}

// Rule 1: ignore any path within a mount point that is of the given filesystem type unconditionally
if len(conditionalPaths) == 0 {
if !ignorable {
// we've matched on the most specific path at this point, which means we should stop searching
// mount points for this path
Expand Down Expand Up @@ -151,7 +151,7 @@ func simpleClean(p string) string {
return "."
}
if p == "/" {
return "/"
return ""
}
return strings.TrimSuffix(p, "/")
}
37 changes: 37 additions & 0 deletions syft/internal/fileresolver/path_skipper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,43 @@ func Test_newPathSkipper(t *testing.T) {
},
},
},
{
name: "buildkit github ubuntu 22.04",
root: "/run/src/core/sbom",
mounts: []*mountinfo.Info{
{Mountpoint: "/", FSType: "overlay"},
{Mountpoint: "/proc", FSType: "proc"},
{Mountpoint: "/dev", FSType: "tmpfs"},
{Mountpoint: "/dev/pts", FSType: "devpts"},
{Mountpoint: "/dev/shm", FSType: "tmpfs"},
{Mountpoint: "/dev/mqueue", FSType: "mqueue"},
{Mountpoint: "/sys", FSType: "sysfs"},
{Mountpoint: "/etc/resolv.conf", FSType: "ext4"},
{Mountpoint: "/etc/hosts", FSType: "ext4"},
{Mountpoint: "/sys/fs/cgroup", FSType: "cgroup2"},
{Mountpoint: "/run/out", FSType: "ext4"},
{Mountpoint: "/run/src/core/sbom", FSType: "overlay"},
{Mountpoint: "/tmp", FSType: "tmpfs"},
{Mountpoint: "/dev/otel-grpc.sock", FSType: "overlay"},
{Mountpoint: "/proc/bus", FSType: "proc"},
{Mountpoint: "/proc/fs", FSType: "proc"},
{Mountpoint: "/proc/irq", FSType: "proc"},
{Mountpoint: "/proc/sys", FSType: "proc"},
{Mountpoint: "/proc/sysrq-trigger", FSType: "proc"},
{Mountpoint: "/proc/acpi", FSType: "tmpfs"},
{Mountpoint: "/proc/kcore", FSType: "tmpfs"},
{Mountpoint: "/proc/keys", FSType: "tmpfs"},
{Mountpoint: "/proc/latency_stats", FSType: "tmpfs"},
{Mountpoint: "/proc/timer_list", FSType: "tmpfs"},
{Mountpoint: "/sys/firmware", FSType: "tmpfs"},
{Mountpoint: "/proc/scsi", FSType: "tmpfs"},
},
want: []expect{
{
path: "/run/src/core/sbom",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 17f3ee9

Please sign in to comment.