machine: prepend LocalhostSSHArgs to args

Rather than append LocalhostSSHArgs to args, prepend it, assuming the
order doesn't matter here.

This fixes the following prealloc warning (without decreasing
readability):

> cmd/podman/machine/cp.go:130:2: Consider preallocating args (prealloc)
> 	args := []string{"-r", "-i", sshConfig.IdentityPath, "-P", strconv.Itoa(sshConfig.Port)}
> 	^

This commit is part of series fixing issues reported by prealloc linter
from golangci-lint v2.8.0.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2026-02-05 16:40:05 -08:00
parent b046387979
commit 2a99655120
2 changed files with 10 additions and 5 deletions

View File

@@ -127,10 +127,12 @@ func localhostSSHCopy(opts *cpOptions) error {
destPath = username + destPath
}
args := []string{"-r", "-i", sshConfig.IdentityPath, "-P", strconv.Itoa(sshConfig.Port)}
args = append(args, machine.LocalhostSSHArgs()...) // Warning: This MUST NOT be generalized to allow communication over untrusted networks.
args = append(args, []string{srcPath, destPath}...)
args := append(
machine.LocalhostSSHArgs(), // Warning: This MUST NOT be generalized to allow communication over untrusted networks.
"-r",
"-i", sshConfig.IdentityPath,
"-P", strconv.Itoa(sshConfig.Port),
srcPath, destPath)
cmd := exec.Command("scp", args...)
if !opts.Quiet {
cmd.Stdout = os.Stdout

View File

@@ -127,7 +127,10 @@ func localhostNativeSSH(username, identityPath, name string, sshPort int, inputA
port := strconv.Itoa(sshPort)
interactive := true
args := append([]string{"-i", identityPath, "-p", port, sshDestination}, LocalhostSSHArgs()...) // WARNING: This MUST NOT be generalized to allow communication over untrusted networks.
args := append(LocalhostSSHArgs(), // WARNING: This MUST NOT be generalized to allow communication over untrusted networks.
"-i", identityPath,
"-p", port,
sshDestination)
if len(inputArgs) > 0 {
// on the other condition, the term is forced
// anyway