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