Skip to content

Commit

Permalink
introduce skipThis to keep the godirwalk.SkipThis semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcacheux committed Feb 27, 2025
1 parent 965f015 commit 7ca655a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pkg/util/cgroups/pid_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (pm *procPidMapper) refreshMapping(cacheValidity time.Duration) {

pid, err := strconv.ParseInt(de.Name(), 10, 0)
if err != nil {
return filepath.SkipDir
return skipThis(de)
}

cgroupIdentifier, err := IdentiferFromCgroupReferences(pm.procPath, de.Name(), pm.cgroupController, pm.readerFilter)
Expand All @@ -181,7 +181,7 @@ func (pm *procPidMapper) refreshMapping(cacheValidity time.Duration) {
cgroupPidMapping[cgroupIdentifier] = append(cgroupPidMapping[cgroupIdentifier], int(pid))
}

return filepath.SkipDir
return skipThis(de)
})

pm.refreshTimestamp = time.Now()
Expand All @@ -192,6 +192,17 @@ func (pm *procPidMapper) refreshMapping(cacheValidity time.Duration) {
}
}

// skipThis is a helper to skip only the currently processed entry.
// filepath.SkipDir will skip the given entry if it's a directory,
// but it will skip unvisited entries of the parent if it's a file
// which is not what we want usually.
func skipThis(de fs.DirEntry) error {
if de.IsDir() {
return filepath.SkipDir
}
return nil
}

//nolint:revive // TODO(CINT) Fix revive linter
func (pm *procPidMapper) getPIDsForCgroup(identifier, relativeCgroupPath string, cacheValidity time.Duration) []int {
pm.lock.Lock()
Expand Down

0 comments on commit 7ca655a

Please sign in to comment.