Skip to content

Commit

Permalink
Should not exclude a disk if only a partition is excluded
Browse files Browse the repository at this point in the history
Signed-off-by: Weihang Lo <[email protected]>
  • Loading branch information
weihanglo authored and gitlawr committed Oct 8, 2021
1 parent 9fd8b94 commit 56e1bc3
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions pkg/filter/path_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,52 @@ var (
defaultExcludedPaths = []string{pathFilterDefaultRoot}
)

type pathFilter struct {
type partPathFilter struct {
excludePaths []string
}

type diskPathFilter struct {
excludePaths []string
}

func RegisterPathFilter(filters string) *Filter {
vf := &pathFilter{}
f := &partPathFilter{}

// add default exclude paths
vf.excludePaths = append(vf.excludePaths, defaultExcludedPaths...)
f.excludePaths = append(f.excludePaths, defaultExcludedPaths...)

if filters != "" {
vf.excludePaths = append(vf.excludePaths, strings.Split(filters, ",")...)
f.excludePaths = append(f.excludePaths, strings.Split(filters, ",")...)
}

return &Filter{
Name: pathFilterName,
DiskFilter: vf,
PartFilter: f,
DiskFilter: &diskPathFilter{excludePaths: f.excludePaths},
}
}

// Exclude returns true if mount path of the disk or partitions is matched
func (pf *pathFilter) Exclude(disk *block.Disk) bool {
if len(pf.excludePaths) == 0 {
// Exclude returns true if mount path of the partition is matched
func (f *partPathFilter) Exclude(part *block.Partition) bool {
if len(f.excludePaths) == 0 {
return true
}

if util.ContainsIgnoredCase(pf.excludePaths, disk.FileSystemInfo.MountPoint) {
if util.ContainsIgnoredCase(f.excludePaths, part.FileSystemInfo.MountPoint) {
return true
}

for _, part := range disk.Partitions {
if util.ContainsIgnoredCase(pf.excludePaths, part.FileSystemInfo.MountPoint) {
return true
}
return false
}

// Exclude returns true if mount path of the disk is matched
func (f *diskPathFilter) Exclude(disk *block.Disk) bool {
if len(f.excludePaths) == 0 {
return true
}

if util.ContainsIgnoredCase(f.excludePaths, disk.FileSystemInfo.MountPoint) {
return true
}

return false
Expand Down

0 comments on commit 56e1bc3

Please sign in to comment.