Skip to content

Commit

Permalink
merge #503 into opencontainers/umoci:main
Browse files Browse the repository at this point in the history
guoguangwu (1):
  chore: slice loop replace

LGTMs: cyphar
  • Loading branch information
cyphar committed Dec 12, 2023
2 parents 290a73e + 2e83d91 commit bcbd7b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
4 changes: 1 addition & 3 deletions oci/casext/refname_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ func fakeSetupEngine(t *testing.T, engineExt Engine) ([]descriptorMap, error) {
MediaType: ispec.MediaTypeImageManifest,
Config: configDescriptor,
}
for _, layer := range layerDescriptors {
manifest.Layers = append(manifest.Layers, layer)
}
manifest.Layers = append(manifest.Layers, layerDescriptors...)

manifestDigest, manifestSize, err := engineExt.PutBlobJSON(ctx, manifest)
if err != nil {
Expand Down
28 changes: 7 additions & 21 deletions oci/config/generate/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ func (g *Generator) AddConfigEnv(name, value string) {
// ConfigEnv returns the list of environment variables to be used in a container.
func (g *Generator) ConfigEnv() []string {
copy := []string{}
for _, v := range g.image.Config.Env {
copy = append(copy, v)
}
copy = append(copy, g.image.Config.Env...)
return copy
}

Expand All @@ -176,19 +174,15 @@ func (g *Generator) ClearConfigEntrypoint() {
// SetConfigEntrypoint sets the list of arguments to use as the command to execute when the container starts.
func (g *Generator) SetConfigEntrypoint(entrypoint []string) {
copy := []string{}
for _, v := range entrypoint {
copy = append(copy, v)
}
copy = append(copy, entrypoint...)
g.image.Config.Entrypoint = copy
}

// ConfigEntrypoint returns the list of arguments to use as the command to execute when the container starts.
func (g *Generator) ConfigEntrypoint() []string {
// We have to make a copy to preserve the privacy of g.image.Config.
copy := []string{}
for _, v := range g.image.Config.Entrypoint {
copy = append(copy, v)
}
copy = append(copy, g.image.Config.Entrypoint...)
return copy
}

Expand All @@ -200,19 +194,15 @@ func (g *Generator) ClearConfigCmd() {
// SetConfigCmd sets the list of default arguments to the entrypoint of the container.
func (g *Generator) SetConfigCmd(cmd []string) {
copy := []string{}
for _, v := range cmd {
copy = append(copy, v)
}
copy = append(copy, cmd...)
g.image.Config.Cmd = copy
}

// ConfigCmd returns the list of default arguments to the entrypoint of the container.
func (g *Generator) ConfigCmd() []string {
// We have to make a copy to preserve the privacy of g.image.Config.
copy := []string{}
for _, v := range g.image.Config.Cmd {
copy = append(copy, v)
}
copy = append(copy, g.image.Config.Cmd...)
return copy
}

Expand Down Expand Up @@ -309,9 +299,7 @@ func (g *Generator) AddRootfsDiffID(diffid digest.Digest) {
// RootfsDiffIDs returns the the array of layer content hashes (DiffIDs), in order from bottom-most to top-most.
func (g *Generator) RootfsDiffIDs() []digest.Digest {
copy := []digest.Digest{}
for _, v := range g.image.RootFS.DiffIDs {
copy = append(copy, v)
}
copy = append(copy, g.image.RootFS.DiffIDs...)
return copy
}

Expand All @@ -328,9 +316,7 @@ func (g *Generator) AddHistory(history ispec.History) {
// History returns the history of each layer.
func (g *Generator) History() []ispec.History {
copy := []ispec.History{}
for _, v := range g.image.History {
copy = append(copy, v)
}
copy = append(copy, g.image.History...)
return copy
}

Expand Down

0 comments on commit bcbd7b0

Please sign in to comment.