Skip to content

Commit f7f6aab

Browse files
committed
oci: fix superfluous slice operations
Signed-off-by: Iceber Gu <[email protected]>
1 parent 2bc8c77 commit f7f6aab

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

oci/spec_opts.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,7 @@ func WithLinuxNamespace(ns specs.LinuxNamespace) SpecOpts {
294294
setLinux(s)
295295
for i, n := range s.Linux.Namespaces {
296296
if n.Type == ns.Type {
297-
before := s.Linux.Namespaces[:i]
298-
after := s.Linux.Namespaces[i+1:]
299-
s.Linux.Namespaces = append(before, ns)
300-
s.Linux.Namespaces = append(s.Linux.Namespaces, after...)
297+
s.Linux.Namespaces[i] = ns
301298
return nil
302299
}
303300
}
@@ -930,33 +927,27 @@ func WithReadonlyPaths(paths []string) SpecOpts {
930927

931928
// WithWriteableSysfs makes any sysfs mounts writeable
932929
func WithWriteableSysfs(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
933-
for i, m := range s.Mounts {
930+
for _, m := range s.Mounts {
934931
if m.Type == "sysfs" {
935-
var options []string
936-
for _, o := range m.Options {
932+
for i, o := range m.Options {
937933
if o == "ro" {
938-
o = "rw"
934+
m.Options[i] = "rw"
939935
}
940-
options = append(options, o)
941936
}
942-
s.Mounts[i].Options = options
943937
}
944938
}
945939
return nil
946940
}
947941

948942
// WithWriteableCgroupfs makes any cgroup mounts writeable
949943
func WithWriteableCgroupfs(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
950-
for i, m := range s.Mounts {
944+
for _, m := range s.Mounts {
951945
if m.Type == "cgroup" {
952-
var options []string
953-
for _, o := range m.Options {
946+
for i, o := range m.Options {
954947
if o == "ro" {
955-
o = "rw"
948+
m.Options[i] = "rw"
956949
}
957-
options = append(options, o)
958950
}
959-
s.Mounts[i].Options = options
960951
}
961952
}
962953
return nil

0 commit comments

Comments
 (0)