mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-05 00:15:44 +00:00
Replace strings.Split(..)[0] with strings.Cut
These places were ignored by modernize, so I did some grepping and editing. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
63166293c8
commit
bf78f80b00
7 changed files with 10 additions and 8 deletions
|
|
@ -228,7 +228,7 @@ func determineTargetCtrAndCmd(args []string, latestSpecified bool, execCidFilePr
|
|||
if err != nil {
|
||||
return "", nil, fmt.Errorf("reading CIDFile: %w", err)
|
||||
}
|
||||
nameOrID = strings.Split(string(content), "\n")[0]
|
||||
nameOrID, _, _ = strings.Cut(string(content), "\n")
|
||||
}
|
||||
}
|
||||
return nameOrID, command, nil
|
||||
|
|
|
|||
|
|
@ -384,7 +384,7 @@ func (c *Container) generateInspectContainerConfig(spec *spec.Spec) *define.Insp
|
|||
envSecrets := c.config.EnvSecrets
|
||||
for envIndex, envValue := range ctrConfig.Env {
|
||||
// env variables come in the style `name=value`
|
||||
envName := strings.Split(envValue, "=")[0]
|
||||
envName, _, _ := strings.Cut(envValue, "=")
|
||||
|
||||
_, ok := envSecrets[envName]
|
||||
if ok {
|
||||
|
|
|
|||
|
|
@ -885,8 +885,8 @@ func transferRootful(source entities.ScpTransferImageOptions, dest entities.ScpT
|
|||
var uSave *user.User
|
||||
var uLoad *user.User
|
||||
var err error
|
||||
source.User = strings.Split(source.User, ":")[0] // split in case provided with uid:gid
|
||||
dest.User = strings.Split(dest.User, ":")[0]
|
||||
source.User, _, _ = strings.Cut(source.User, ":") // In case of uid:gid.
|
||||
dest.User, _, _ = strings.Cut(dest.User, ":")
|
||||
uSave, err = lookupUser(source.User)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -361,7 +361,7 @@ func ParseImageSCPArg(arg string) (*entities.ScpTransferImageOptions, []string,
|
|||
|
||||
switch {
|
||||
case strings.Contains(arg, "@localhost::"): // image transfer between users
|
||||
location.User = strings.Split(arg, "@")[0]
|
||||
location.User, _, _ = strings.Cut(arg, "@")
|
||||
location, err = ValidateImagePortion(location, arg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ func securityConfigureGenerator(s *specgen.SpecGenerator, g *generate.Generator,
|
|||
configSpec.Process.Capabilities.Inheritable = []string{}
|
||||
configSpec.Process.Capabilities.Bounding = caplist
|
||||
|
||||
user := strings.Split(s.User, ":")[0]
|
||||
user, _, _ := strings.Cut(s.User, ":")
|
||||
|
||||
if (user == "" && s.UserNS.NSMode != specgen.KeepID) || user == "root" || user == "0" {
|
||||
configSpec.Process.Capabilities.Effective = caplist
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ func ReadPodIDFile(path string) (string, error) {
|
|||
if err != nil {
|
||||
return "", fmt.Errorf("reading pod ID file: %w", err)
|
||||
}
|
||||
return strings.Split(string(content), "\n")[0], nil
|
||||
id, _, _ := strings.Cut(string(content), "\n")
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// ReadPodIDFiles reads the specified files and returns their content (i.e.,
|
||||
|
|
|
|||
|
|
@ -796,7 +796,8 @@ func ConvertContainer(container *parser.UnitFile, unitsInfoMap map[string]*UnitI
|
|||
for _, device := range devices {
|
||||
if device[0] == '-' {
|
||||
device = device[1:]
|
||||
_, err := os.Stat(strings.Split(device, ":")[0])
|
||||
file, _, _ := strings.Cut(device, ":")
|
||||
_, err := os.Stat(file)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue