1
0
mirror of https://github.com/containers/buildah.git synced 2025-04-18 07:04:05 +03:00

Use slices.Contains

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2025-04-07 12:23:13 -07:00
parent 17777cf8ac
commit 84a3905f61
6 changed files with 16 additions and 31 deletions

View File

@ -221,10 +221,8 @@ func TestProcessEnv(t *testing.T) {
g.AddProcessEnv("PARENT_TEST_PID", strconv.Itoa(unix.Getpid()))
},
func(t *testing.T, report *types.TestReport) {
for _, ev := range report.Spec.Process.Env {
if ev == e {
return
}
if slices.Contains(report.Spec.Process.Env, e) {
return
}
t.Fatalf("expected environment variable %q", e)
},

View File

@ -173,14 +173,7 @@ func (s *StageExecutor) Preserve(path string) error {
for cachedPath := range s.volumeCache {
// Walk our list of cached volumes, and check that they're
// still in the list of locations that we need to cache.
found := false
for _, volume := range s.volumes {
if volume == cachedPath {
// We need to keep this volume's cache.
found = true
break
}
}
found := slices.Contains(s.volumes, cachedPath)
if !found {
// We don't need to keep this volume's cache. Make a
// note to remove it.

View File

@ -1,6 +1,10 @@
package sbom
import "github.com/containers/buildah/define"
import (
"slices"
"github.com/containers/buildah/define"
)
// Preset returns a predefined SBOMScanOptions structure that has the passed-in
// name as one of its "Type" values.
@ -55,10 +59,8 @@ func Preset(name string) (preset *define.SBOMScanOptions, err error) {
},
}
for _, preset := range presets {
for _, presetName := range preset.Type {
if presetName == name {
return &preset, nil
}
if slices.Contains(preset.Type, name) {
return &preset, nil
}
}
return nil, nil

6
new.go
View File

@ -99,10 +99,8 @@ func newContainerIDMappingOptions(idmapOptions *define.IDMappingOptions) storage
func containerNameExist(name string, containers []storage.Container) bool {
for _, container := range containers {
for _, cname := range container.Names {
if cname == name {
return true
}
if slices.Contains(container.Names, name) {
return true
}
}
return false

View File

@ -68,10 +68,8 @@ func GenBuildOptions(c *cobra.Command, inputArgs []string, iopts BuildOptions) (
tags = tags[1:]
}
if c.Flag("manifest").Changed {
for _, tag := range tags {
if tag == iopts.Manifest {
return options, nil, nil, errors.New("the same name must not be specified for both '--tag' and '--manifest'")
}
if slices.Contains(tags, iopts.Manifest) {
return options, nil, nil, errors.New("the same name must not be specified for both '--tag' and '--manifest'")
}
}
}

View File

@ -335,12 +335,8 @@ func logIfNotErrno(err error, what string, ignores ...syscall.Errno) (logged boo
if err == nil {
return false
}
if errno, isErrno := err.(syscall.Errno); isErrno {
for _, ignore := range ignores {
if errno == ignore {
return false
}
}
if errno, ok := err.(syscall.Errno); ok && slices.Contains(ignores, errno) {
return false
}
logrus.Error(what)
return true