mirror of
https://github.com/containers/podman.git
synced 2026-03-13 08:01:19 +08:00
Don't use strings.Split(fmt.Sprintf("--a b ...", ...), " ")
When we have the _precise_ knowledge of where the parameter boundaries are, and an API that allows us to express that, just _do that_ instead of completely unnecessarily worrying about spaces in parameter values. Also, this allows us to format the code to make the option and value correspondence much easier to see. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
@@ -333,18 +333,20 @@ func ExecPodman(dest entities.ScpTransferImageOptions, podman string, command []
|
||||
|
||||
// CreateCommands forms the podman save and load commands used by SCP
|
||||
func CreateCommands(source entities.ScpTransferImageOptions, dest entities.ScpTransferImageOptions, opts entities.ScpCreateCommandsOptions) ([]string, []string) {
|
||||
var parentString string
|
||||
quiet := ""
|
||||
if source.Quiet {
|
||||
quiet = "-q "
|
||||
}
|
||||
loadCmd := []string{opts.Podman}
|
||||
saveCmd := []string{opts.Podman}
|
||||
if len(opts.ParentFlags) > 0 {
|
||||
parentString = strings.Join(opts.ParentFlags, " ") + " " // if there are parent args, an extra space needs to be added
|
||||
} else {
|
||||
parentString = strings.Join(opts.ParentFlags, " ")
|
||||
loadCmd = append(loadCmd, opts.ParentFlags...)
|
||||
saveCmd = append(saveCmd, opts.ParentFlags...)
|
||||
}
|
||||
loadCmd := strings.Split(fmt.Sprintf("%s %sload %s--input %s", opts.Podman, parentString, quiet, dest.File), " ")
|
||||
saveCmd := strings.Split(fmt.Sprintf("%s %vsave %s--output %s %s", opts.Podman, parentString, quiet, source.File, source.Image), " ")
|
||||
loadCmd = append(loadCmd, "load")
|
||||
saveCmd = append(saveCmd, "save")
|
||||
if source.Quiet {
|
||||
loadCmd = append(loadCmd, "-q")
|
||||
saveCmd = append(saveCmd, "-q")
|
||||
}
|
||||
loadCmd = append(loadCmd, "--input", dest.File)
|
||||
saveCmd = append(saveCmd, "--output", source.File, source.Image)
|
||||
return saveCmd, loadCmd
|
||||
}
|
||||
|
||||
|
||||
@@ -1314,9 +1314,9 @@ func (p *PodmanTestIntegration) makeOptions(args []string, options PodmanExecOpt
|
||||
return args
|
||||
}
|
||||
|
||||
var debug string
|
||||
podmanOptions := []string{}
|
||||
if _, ok := os.LookupEnv("E2E_DEBUG"); ok {
|
||||
debug = "--log-level=debug --syslog=true "
|
||||
podmanOptions = append(podmanOptions, "--log-level=debug", "--syslog=true")
|
||||
}
|
||||
|
||||
eventsType := "file"
|
||||
@@ -1324,8 +1324,16 @@ func (p *PodmanTestIntegration) makeOptions(args []string, options PodmanExecOpt
|
||||
eventsType = "none"
|
||||
}
|
||||
|
||||
podmanOptions := strings.Split(fmt.Sprintf("%s--root %s --runroot %s --runtime %s --conmon %s --network-config-dir %s --cgroup-manager %s --tmpdir %s --events-backend %s",
|
||||
debug, p.Root, p.RunRoot, p.OCIRuntime, p.ConmonBinary, p.NetworkConfigDir, p.CgroupManager, p.TmpDir, eventsType), " ")
|
||||
podmanOptions = append(podmanOptions,
|
||||
"--root", p.Root,
|
||||
"--runroot", p.RunRoot,
|
||||
"--runtime", p.OCIRuntime,
|
||||
"--conmon", p.ConmonBinary,
|
||||
"--network-config-dir", p.NetworkConfigDir,
|
||||
"--cgroup-manager", p.CgroupManager,
|
||||
"--tmpdir", p.TmpDir,
|
||||
"--events-backend", eventsType,
|
||||
)
|
||||
|
||||
podmanOptions = append(podmanOptions, strings.Split(p.StorageOptions, " ")...)
|
||||
if !options.NoCache {
|
||||
|
||||
@@ -122,8 +122,16 @@ func (p *PodmanTestIntegration) StopRemoteService() {
|
||||
// getRemoteOptions assembles all the podman main options
|
||||
func getRemoteOptions(p *PodmanTestIntegration, args []string) []string {
|
||||
networkDir := p.NetworkConfigDir
|
||||
podmanOptions := strings.Split(fmt.Sprintf("--root %s --runroot %s --runtime %s --conmon %s --network-config-dir %s --cgroup-manager %s --tmpdir %s --events-backend %s",
|
||||
p.Root, p.RunRoot, p.OCIRuntime, p.ConmonBinary, networkDir, p.CgroupManager, p.TmpDir, "file"), " ")
|
||||
podmanOptions := []string{
|
||||
"--root", p.Root,
|
||||
"--runroot", p.RunRoot,
|
||||
"--runtime", p.OCIRuntime,
|
||||
"--conmon", p.ConmonBinary,
|
||||
"--network-config-dir", networkDir,
|
||||
"--cgroup-manager", p.CgroupManager,
|
||||
"--tmpdir", p.TmpDir,
|
||||
"--events-backend", "file",
|
||||
}
|
||||
|
||||
podmanOptions = append(podmanOptions, strings.Split(p.StorageOptions, " ")...)
|
||||
podmanOptions = append(podmanOptions, args...)
|
||||
|
||||
Reference in New Issue
Block a user