8000 fix: de-duplicate same `dpkg` packages with different filePaths from different layers by DmitriyLewen · Pull Request #8298 · aquasecurity/trivy · GitHub
[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: de-duplicate same dpkg packages with different filePaths from different layers #8298

Merged
merged 3 commits into from
Jan 28, 2025

Conversation

DmitriyLewen
Copy link
Contributor

Description

See #8297

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@DmitriyLewen DmitriyLewen self-assigned this Jan 27, 2025
@DmitriyLewen DmitriyLewen changed the title fix(dpkg): de-duplicate same packages with different filePaths from different layers fix: de-duplicate same dpkg packages with different filePaths from different layers Jan 27, 2025
@DmitriyLewen DmitriyLewen marked this pull request as ready for review January 27, 2025 12:06
packages := lo.UniqBy(mergedLayer.Packages, func(pkg ftypes.Package) string {
return cmp.Or(pkg.ID, fmt.Sprintf("%s@%s", pkg.Name, utils.FormatVersion(pkg)))
})
mergedLayer.Packages = lo.Ternary(len(packages) > 0, packages, nil)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this conversion is needed in many places, we may want to define a utility function somewhere, like:

func NilIfEmpty[T any](s []T) []T {
    if len(s) == 0 {
        return nil
    }
    return s
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm.. we already have this function 😄 :

func ZeroToNil[T any](t []T) []T {
if len(t) == 0 {
return nil
}
return t
}

Used this function in 4f939b7

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, we already have it 😄

@knqyf263 knqyf263 enabled auto-merge January 28, 2025 06:46
@knqyf263 knqyf263 added this pull request to the merge queue Jan 28, 2025
Merged via the queue into aquasecurity:main with commit 846498d Jan 28, 2025
12 checks passed
RingoDev pushed a commit to RingoDev/trivy that referenced this pull request Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix(dpkg): de-duplicate same packages with different filePaths from different layers
2 participants
0