mirror of
https://github.com/containers/podman.git
synced 2026-03-13 08:01:19 +08:00
run modernize -fix ./...
modernize seems to be smarter now so it found some more things that are not even go 1.25 related. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@@ -21,13 +21,13 @@ func TestPodOptions(t *testing.T) {
|
||||
cc := reflect.ValueOf(&exampleOptions).Elem()
|
||||
pc := reflect.ValueOf(&podOptions).Elem()
|
||||
|
||||
pcType := reflect.TypeOf(podOptions)
|
||||
pcType := reflect.TypeFor[entities.PodCreateOptions]()
|
||||
for i := 0; i < pc.NumField(); i++ {
|
||||
podField := pc.FieldByIndex([]int{i})
|
||||
podType := pcType.Field(i)
|
||||
for j := 0; j < cc.NumField(); j++ {
|
||||
containerField := cc.FieldByIndex([]int{j})
|
||||
containerType := reflect.TypeOf(exampleOptions).Field(j)
|
||||
containerType := reflect.TypeFor[entities.ContainerCreateOptions]().Field(j)
|
||||
tagPod := strings.Split(podType.Tag.Get("json"), ",")[0]
|
||||
tagContainer := strings.Split(containerType.Tag.Get("json"), ",")[0]
|
||||
if tagPod == tagContainer && (tagPod != "" && tagContainer != "") {
|
||||
|
||||
@@ -70,7 +70,7 @@ func autocompleteMachineSSH(_ *cobra.Command, args []string, toComplete string)
|
||||
// autocompleteMachineCp - Autocomplete machine cp command.
|
||||
func autocompleteMachineCp(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
if len(args) < 2 {
|
||||
if i := strings.IndexByte(toComplete, ':'); i > -1 {
|
||||
if found := strings.Contains(toComplete, ":"); found {
|
||||
// TODO: offer virtual machine path completion
|
||||
|
||||
// the user already set the machine name, so don't use the host file autocompletion
|
||||
|
||||
@@ -316,14 +316,14 @@ func isUnambiguousName(imageName string) bool {
|
||||
}
|
||||
|
||||
// Otherwise we require a fully qualified name
|
||||
firstSlash := strings.Index(imageName, "/")
|
||||
if firstSlash == -1 {
|
||||
before, _, ok := strings.Cut(imageName, "/")
|
||||
if !ok {
|
||||
// No domain or path, not fully qualified
|
||||
return false
|
||||
}
|
||||
|
||||
// What is before the first slash can be a domain or a path
|
||||
domain := imageName[:firstSlash]
|
||||
domain := before
|
||||
|
||||
// If its a domain (has dot or port or is "localhost") it is considered fq
|
||||
if strings.ContainsAny(domain, ".:") || domain == "localhost" {
|
||||
|
||||
@@ -2583,7 +2583,7 @@ func (c *Container) groupEntry(groupname, gid string, list []string) string {
|
||||
// Returns password entry (as a string that can be appended to /etc/passwd) and
|
||||
// any error that occurred.
|
||||
func (c *Container) generatePasswdEntry() (string, error) {
|
||||
passwdString := ""
|
||||
var passwdString strings.Builder
|
||||
|
||||
addedUID := 0
|
||||
for _, userid := range c.config.HostUsers {
|
||||
@@ -2596,14 +2596,14 @@ func (c *Container) generatePasswdEntry() (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
passwdString += entry
|
||||
passwdString.WriteString(entry)
|
||||
}
|
||||
if c.config.AddCurrentUserPasswdEntry {
|
||||
entry, uid, _, err := c.generateCurrentUserPasswdEntry()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
passwdString += entry
|
||||
passwdString.WriteString(entry)
|
||||
addedUID = uid
|
||||
}
|
||||
if c.config.User != "" {
|
||||
@@ -2611,10 +2611,10 @@ func (c *Container) generatePasswdEntry() (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
passwdString += entry
|
||||
passwdString.WriteString(entry)
|
||||
}
|
||||
|
||||
return passwdString, nil
|
||||
return passwdString.String(), nil
|
||||
}
|
||||
|
||||
// generateCurrentUserPasswdEntry generates an /etc/passwd entry for the user
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package libpod
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/opencontainers/runtime-tools/generate"
|
||||
@@ -94,13 +95,7 @@ func TestInjectEnvSecrets(t *testing.T) {
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
for key, val := range tt.expectedEnv {
|
||||
found := false
|
||||
for _, env := range g.Config.Process.Env {
|
||||
if env == key+"="+val {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
found := slices.Contains(g.Config.Process.Env, key+"="+val)
|
||||
assert.True(t, found, "Expected env %s=%s not found", key, val)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,9 +554,7 @@ func ManifestModify(w http.ResponseWriter, r *http.Request) {
|
||||
// If the data was multipart, then save items from it into a
|
||||
// directory that will be removed along with this list,
|
||||
// whenever that happens.
|
||||
artifactExtraction.Add(1)
|
||||
go func() {
|
||||
defer artifactExtraction.Done()
|
||||
artifactExtraction.Go(func() {
|
||||
storageConfig := runtime.StorageConfig()
|
||||
// FIXME: knowing that this is the location of the
|
||||
// per-image-record-stuff directory is a little too
|
||||
@@ -618,7 +616,7 @@ func ManifestModify(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
// Save the list of files that we created.
|
||||
body.ArtifactFiles = contentFiles
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
if tlsVerify, ok := r.URL.Query()["tlsVerify"]; ok {
|
||||
|
||||
@@ -146,15 +146,9 @@ func jsonProgressToString(p *jsonstream.Progress) string {
|
||||
}
|
||||
}
|
||||
|
||||
percentage := int(float64(p.Current)/float64(p.Total)*100) / 2
|
||||
if percentage > 50 {
|
||||
percentage = 50
|
||||
}
|
||||
percentage := min(int(float64(p.Current)/float64(p.Total)*100)/2, 50)
|
||||
|
||||
numSpaces := 0
|
||||
if 50-percentage > 0 {
|
||||
numSpaces = 50 - percentage
|
||||
}
|
||||
numSpaces := max(50-percentage, 0)
|
||||
pbBox = fmt.Sprintf("[%s>%s] ", strings.Repeat("=", percentage), strings.Repeat(" ", numSpaces))
|
||||
|
||||
switch {
|
||||
|
||||
@@ -296,8 +296,8 @@ func getFileName(resp *http.Response, fileURL string) (string, error) {
|
||||
cd := resp.Header.Get("Content-Disposition")
|
||||
if cd != "" {
|
||||
const prefix = "filename="
|
||||
if idx := strings.Index(cd, prefix); idx != -1 {
|
||||
filename := cd[idx+len(prefix):]
|
||||
if _, after, ok := strings.Cut(cd, prefix); ok {
|
||||
filename := after
|
||||
filename = strings.Trim(filename, "\"'")
|
||||
return filename, nil
|
||||
}
|
||||
@@ -471,8 +471,8 @@ func parseMultiQuadletFile(filePath string) ([]quadletSection, error) {
|
||||
// extractFileNameFromSection extracts the FileName from a comment in the quadlet section
|
||||
// The comment must be in the format: # FileName=my-name
|
||||
func extractFileNameFromSection(content string) (string, error) {
|
||||
lines := strings.Split(content, "\n")
|
||||
for _, line := range lines {
|
||||
lines := strings.SplitSeq(content, "\n")
|
||||
for line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
// Look for comment lines starting with #
|
||||
if strings.HasPrefix(line, "#") {
|
||||
@@ -499,8 +499,8 @@ func extractFileNameFromSection(content string) (string, error) {
|
||||
// Returns the appropriate file extension (.container, .volume, .network, etc.)
|
||||
func detectQuadletType(content string) (string, error) {
|
||||
// Look for section headers like [Container], [Volume], [Network], etc.
|
||||
lines := strings.Split(content, "\n")
|
||||
for _, line := range lines {
|
||||
lines := strings.SplitSeq(content, "\n")
|
||||
for line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
|
||||
sectionName := strings.ToLower(strings.Trim(line, "[]"))
|
||||
|
||||
@@ -134,8 +134,8 @@ func parseUids(colonDelimitKeys []byte) []string {
|
||||
parseduid := uid
|
||||
if ltidx := strings.Index(uid, "<"); ltidx != -1 {
|
||||
subuid := parseduid[ltidx+1:]
|
||||
if gtidx := strings.Index(subuid, ">"); gtidx != -1 {
|
||||
parseduid = subuid[:gtidx]
|
||||
if before, _, ok := strings.Cut(subuid, ">"); ok {
|
||||
parseduid = before
|
||||
}
|
||||
}
|
||||
parseduids = append(parseduids, parseduid)
|
||||
|
||||
@@ -86,7 +86,7 @@ var _ = Describe("Podman images", func() {
|
||||
output := session.OutputToString()
|
||||
Expect(output).To(BeValidJSON())
|
||||
|
||||
images := []map[string]interface{}{}
|
||||
images := []map[string]any{}
|
||||
err := json.Unmarshal([]byte(output), &images)
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@@ -1573,14 +1573,14 @@ func generateKubeYaml(kind string, object any, pathname string) error {
|
||||
|
||||
// generateMultiDocKubeYaml writes multiple kube objects in one Yaml document.
|
||||
func generateMultiDocKubeYaml(kubeObjects []string, pathname string) error {
|
||||
var multiKube string
|
||||
var multiKube strings.Builder
|
||||
|
||||
for _, k := range kubeObjects {
|
||||
multiKube += "---\n"
|
||||
multiKube += k
|
||||
multiKube.WriteString("---\n")
|
||||
multiKube.WriteString(k)
|
||||
}
|
||||
|
||||
return writeYaml(multiKube, pathname)
|
||||
return writeYaml(multiKube.String(), pathname)
|
||||
}
|
||||
|
||||
func createSecret(podmanTest *PodmanTestIntegration, name string, value []byte) { //nolint:unparam
|
||||
|
||||
@@ -399,10 +399,7 @@ func applyLimitToResults(results map[string]any, limitNum int) map[string]any {
|
||||
|
||||
if limitNum > 0 {
|
||||
if resultsArray, ok := resultsCopy["results"].([]any); ok {
|
||||
actualLimit := limitNum
|
||||
if len(resultsArray) < limitNum {
|
||||
actualLimit = len(resultsArray)
|
||||
}
|
||||
actualLimit := min(len(resultsArray), limitNum)
|
||||
resultsCopy["results"] = resultsArray[:actualLimit]
|
||||
resultsCopy["num_results"] = actualLimit
|
||||
}
|
||||
@@ -491,10 +488,7 @@ func applyPagination(allTags []string, limit int, last string, repoName string)
|
||||
}
|
||||
|
||||
if limit > 0 {
|
||||
endIndex := startIndex + limit
|
||||
if endIndex > len(allTags) {
|
||||
endIndex = len(allTags)
|
||||
}
|
||||
endIndex := min(startIndex+limit, len(allTags))
|
||||
return allTags[startIndex:endIndex]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user