From 8cdc04168d3888c261541b4de02ca72b15b2c1c2 Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: Sep 06 2022 01:08:57 +0000 Subject: Extra arguments now use shell-escaping - revert One of the previous commits (88c2dd8a) resolved the original issue (#587) by changing the design of how are arguments passed to rpmbuild (and other external programs) and this fix is not needed anymore - in fact, both changes are not compatible, thus reverting the most of the code of the original fix. Shell-escaping should not be needed. Relates: #587 Signed-off-by: Ondrej Nosek --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 5ee5502..4d2a13b 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -22,7 +22,6 @@ import os import posixpath import random import re -import shlex import shutil import subprocess import sys @@ -1549,19 +1548,6 @@ class Commands(object): self._run_command(cmd, cwd=self.path) return - def process_extra_args(self, cmd, extra_args, cmd_name='rpmbuild'): - """Ensures that extra args are escaped in shell-compatible way - - :param list cmd: rpm command - :param list extra_args: additional arguments that are passed to - the command. - :param string cmd_name: name of the command, used for debug log - """ - extra_args = list(map(lambda arg: shlex.quote(arg), extra_args)) - cmd.extend(extra_args) - self.log.debug("Extra args '{0}' are passed to {1} " - "command".format(extra_args, cmd_name)) - def clone(self, repo, path=None, branch=None, bare_dir=None, anon=False, target=None, depth=None, extra_args=None): """Clone a repo, optionally check out a specific branch. @@ -1618,7 +1604,9 @@ class Commands(object): # --bare and --origin are incompatible cmd.extend(['--origin', self.default_branch_remote]) if extra_args: - self.process_extra_args(cmd, extra_args, 'git clone') + cmd.extend(extra_args) + self.log.debug("Extra args '{0}' are passed to git clone " + "command".format(extra_args)) if target: self.log.debug('Cloning into: %s', target) cmd.append(target) @@ -2581,7 +2569,9 @@ class Commands(object): for entry in define: cmd.extend(['--define', entry]) if extra_args: - self.process_extra_args(cmd, extra_args) + cmd.extend(extra_args) + self.log.debug("Extra args '{0}' are passed to rpmbuild " + "command".format(extra_args)) if short: cmd.append('--short-circuit') if nocheck: @@ -2655,7 +2645,9 @@ class Commands(object): for entry in define: cmd.extend(['--define', entry]) if extra_args: - self.process_extra_args(cmd, extra_args) + cmd.extend(extra_args) + self.log.debug("Extra args '{0}' are passed to rpmbuild " + "command".format(extra_args)) if short: cmd.append('--short-circuit') if nocheck: @@ -2790,7 +2782,9 @@ class Commands(object): for entry in define: cmd.extend(['--define', entry]) if extra_args: - self.process_extra_args(cmd, extra_args) + cmd.extend(extra_args) + self.log.debug("Extra args '{0}' are passed to rpmbuild " + "command".format(extra_args)) if self.quiet: cmd.append('--quiet') if buildrootdir: @@ -3180,7 +3174,9 @@ class Commands(object): for entry in define: cmd.extend(['--define', entry]) if extra_args: - self.process_extra_args(cmd, extra_args) + cmd.extend(extra_args) + self.log.debug("Extra args '{0}' are passed to rpmbuild " + "command".format(extra_args)) if self.quiet: cmd.append('--quiet') if buildrootdir: @@ -3227,7 +3223,9 @@ class Commands(object): for entry in define: cmd.extend(['--define', entry]) if extra_args: - self.process_extra_args(cmd, extra_args) + cmd.extend(extra_args) + self.log.debug("Extra args '{0}' are passed to rpmbuild " + "command".format(extra_args)) if self.quiet: cmd.append('--quiet') if buildrootdir: @@ -3336,7 +3334,9 @@ class Commands(object): for entry in define: cmd.extend(['--define', entry]) if extra_args: - self.process_extra_args(cmd, extra_args) + cmd.extend(extra_args) + self.log.debug("Extra args '{0}' are passed to rpmbuild " + "command".format(extra_args)) if self.quiet: cmd.append('--quiet') if buildrootdir: diff --git a/tests/test_cli.py b/tests/test_cli.py index dc7d648..254bfac 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -7,7 +7,6 @@ import hashlib import logging import os import re -import shlex import shutil import subprocess import sys @@ -699,7 +698,7 @@ class TestSrpm(CliTestCase): cli.srpm() expected_cmd = ['rpmbuild'] + cli.cmd.rpmdefines + \ - ['--define', shlex.quote('name body'), '--undefine', 'python', '--nodeps', '-bs', + ['--define', 'name body', '--undefine', 'python', '--nodeps', '-bs', os.path.join(cli.cmd.path, cli.cmd.spec)] _run_command.assert_called_once_with(expected_cmd) @@ -794,8 +793,8 @@ class TestPrep(CliTestCase): spec = os.path.join(cli.cmd.path, cli.cmd.spec) rpmbuild = ['rpmbuild'] + cli.cmd.rpmdefines + ['--define', - shlex.quote(first_arg_with_space), - shlex.quote(second_arg_with_space), + first_arg_with_space, + second_arg_with_space, '--nodeps', '-bp', spec] _run_command.assert_called_once_with(rpmbuild)