mirror of
https://github.com/moby/buildkit.git
synced 2026-11-06 05:16:45 +00:00
refactor: replace strutil.DedupeSlice with generic bkslices.Dedupe
Introduce util/bkslices.Dedupe[T] as a generic replacement for the string-only strutil.DedupeSlice. Remove the now unused util/strutil package. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
3 files changed
+18
-33
No files matched your search
@@ -0,0 +1,15 @@
|
||||
package bkslices
|
||||
|
||||
// Dedupe returns the input values in their original order without duplicates.
|
||||
func Dedupe[T comparable](in []T) []T {
|
||||
seen := make(map[T]struct{}, len(in))
|
||||
out := make([]T, 0, len(in))
|
||||
for _, v := range in {
|
||||
if _, ok := seen[v]; ok {
|
||||
continue
|
||||
}
|
||||
seen[v] = struct{}{}
|
||||
out = append(out, v)
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package mountopts
|
||||
|
||||
import (
|
||||
"github.com/containerd/containerd/v2/core/mount"
|
||||
"github.com/moby/buildkit/util/strutil"
|
||||
"github.com/moby/buildkit/util/bkslices"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sys/unix"
|
||||
@@ -59,7 +59,7 @@ func FixUp(mounts []mount.Mount) ([]mount.Mount, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get unprivileged mount flags for %+v", m)
|
||||
}
|
||||
m.Options = strutil.DedupeSlice(append(m.Options, unpriv...))
|
||||
m.Options = bkslices.Dedupe(append(m.Options, unpriv...))
|
||||
mounts[i] = m
|
||||
}
|
||||
return mounts, nil
|
||||
@@ -81,7 +81,7 @@ func FixUpOCI(mounts []specs.Mount) ([]specs.Mount, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get unprivileged mount flags for %+v", m)
|
||||
}
|
||||
m.Options = strutil.DedupeSlice(append(m.Options, unpriv...))
|
||||
m.Options = bkslices.Dedupe(append(m.Options, unpriv...))
|
||||
mounts[i] = m
|
||||
}
|
||||
return mounts, nil
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
Copyright The containerd Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package strutil
|
||||
|
||||
// DedupeSlice is from https://github.com/containerd/nerdctl/blob/v1.2.1/pkg/strutil/strutil.go#L72-L82
|
||||
func DedupeSlice(in []string) []string {
|
||||
m := make(map[string]struct{})
|
||||
var res []string
|
||||
for _, s := range in {
|
||||
if _, ok := m[s]; !ok {
|
||||
res = append(res, s)
|
||||
m[s] = struct{}{}
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
Reference in new issue
Block a user