public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:master commit in: lib/_emerge/, lib/portage/sync/modules/cvs/, lib/portage/tests/ebuild/, ...
@ 2025-01-11 22:50 Mike Gilbert
  0 siblings, 0 replies; only message in thread
From: Mike Gilbert @ 2025-01-11 22:50 UTC (permalink / raw
  To: gentoo-commits

commit:     002cd09b455eae1790f113438a030828edf3ef14
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Sat Jan 11 17:26:59 2025 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Sat Jan 11 20:18:35 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=002cd09b

Remove portage._shell_quote function

Replaced by shlex.quote, shlex.join, or subprocess.run as appropriate.

Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>

 bin/binhost-snapshot                             |  15 ++--
 bin/ebuild                                       |   3 +-
 bin/install.py                                   |   2 +-
 bin/portageq                                     |   5 +-
 lib/_emerge/BinpkgEnvExtractor.py                |   5 +-
 lib/_emerge/BinpkgExtractorAsync.py              |   6 +-
 lib/_emerge/MiscFunctionsProcess.py              |   4 +-
 lib/_emerge/PackagePhase.py                      |   3 +-
 lib/portage/__init__.py                          |  17 ----
 lib/portage/eclass_cache.py                      |   6 +-
 lib/portage/package/ebuild/config.py             |   2 +-
 lib/portage/package/ebuild/doebuild.py           |  63 +++++++-------
 lib/portage/package/ebuild/fetch.py              |   3 +-
 lib/portage/sync/modules/cvs/cvs.py              |  14 ++-
 lib/portage/sync/modules/git/git.py              |  10 +--
 lib/portage/sync/modules/mercurial/mercurial.py  |   6 +-
 lib/portage/sync/modules/svn/svn.py              |  11 +--
 lib/portage/tests/dbapi/test_portdb_cache.py     |   7 +-
 lib/portage/tests/ebuild/meson.build             |   1 -
 lib/portage/tests/ebuild/test_doebuild_spawn.py  |   4 +-
 lib/portage/tests/ebuild/test_shell_quote.py     | 106 -----------------------
 lib/portage/tests/emerge/test_emerge_slot_abi.py |   3 +-
 lib/portage/tests/sync/test_sync_local.py        |  13 +--
 23 files changed, 91 insertions(+), 218 deletions(-)

diff --git a/bin/binhost-snapshot b/bin/binhost-snapshot
index e0ac7c9b9a..7e3079eb9d 100755
--- a/bin/binhost-snapshot
+++ b/bin/binhost-snapshot
@@ -4,6 +4,7 @@
 
 import argparse
 import os
+import subprocess
 import sys
 import textwrap
 
@@ -107,20 +108,18 @@ def main(argv):
     if not os.path.isdir(binhost_dir):
         parser.error(f"binhost_dir could not be created: '{binhost_dir}'")
 
-    cp_opts = "RP"
+    cp_opts = "-RP"
     if options.hardlinks == "n":
         cp_opts += "p"
     else:
         cp_opts += "l"
 
-    cp_cmd = "cp -{} {} {}".format(
-        cp_opts,
-        portage._shell_quote(src_pkg_dir),
-        portage._shell_quote(snapshot_dir),
-    )
+    try:
+        result = subprocess.run(["cp", cp_opts, src_pkg_dir, snapshot_dir])
+    except OSError:
+        result = None
 
-    ret = os.system(cp_cmd)
-    if not (os.WIFEXITED(ret) and os.WEXITSTATUS(ret) == os.EX_OK):
+    if result is None or result.returncode != 0:
         return 1
 
     infile = open(

diff --git a/bin/ebuild b/bin/ebuild
index 113a6214d6..b313094942 100755
--- a/bin/ebuild
+++ b/bin/ebuild
@@ -49,7 +49,6 @@ import portage
 portage._internal_caller = True
 from portage import os
 from portage import _encodings
-from portage import _shell_quote
 from portage import _unicode_encode
 from portage.const import VDB_PATH
 from portage.exception import (
@@ -165,7 +164,7 @@ def main():
     if ebuild_portdir != vdb_path and ebuild_portdir not in portage.portdb.porttrees:
         portdir_overlay = portage.settings.get("PORTDIR_OVERLAY", "")
         os.environ["PORTDIR_OVERLAY"] = (
-            portdir_overlay + " " + _shell_quote(ebuild_portdir)
+            portdir_overlay + " " + shlex.quote(ebuild_portdir)
         )
 
         print(f"Appending {ebuild_portdir} to PORTDIR_OVERLAY...")

diff --git a/bin/install.py b/bin/install.py
index 3c78dae911..dcf9ca5287 100755
--- a/bin/install.py
+++ b/bin/install.py
@@ -174,7 +174,7 @@ def main(args):
         if returncode != os.EX_OK:
             portage.util.writemsg(
                 "!!! install: copy_xattrs failed with the "
-                f"following arguments: {' '.join(portage._shell_quote(x) for x in args)}\n",
+                f"following arguments: {shlex.join(args)}\n",
                 noiselevel=-1,
             )
     return returncode

diff --git a/bin/portageq b/bin/portageq
index 9ef0cb7d62..7d521b6ba5 100755
--- a/bin/portageq
+++ b/bin/portageq
@@ -33,6 +33,7 @@ try:
     signal.signal(signal.SIGUSR1, debug_signal)
 
     import argparse
+    import shlex
     import sys
     import types
 
@@ -882,7 +883,7 @@ try:
                 exit_status = 1
 
             if verbose:
-                print(arg + "=" + portage._shell_quote(value))
+                print(arg + "=" + shlex.quote(value))
             else:
                 print(value)
 
@@ -1441,7 +1442,7 @@ try:
         def elog(elog_funcname, lines):
             cmd = f"source '{os.environ['PORTAGE_BIN_PATH']}/isolated-functions.sh' ; "
             for line in lines:
-                cmd += f"{elog_funcname} {portage._shell_quote(line)} ; "
+                cmd += f"{elog_funcname} {shlex.quote(line)} ; "
             subprocess.call([portage.const.BASH_BINARY, "-c", cmd])
 
     else:

diff --git a/lib/_emerge/BinpkgEnvExtractor.py b/lib/_emerge/BinpkgEnvExtractor.py
index 7ce30548ad..8e55b7c60a 100644
--- a/lib/_emerge/BinpkgEnvExtractor.py
+++ b/lib/_emerge/BinpkgEnvExtractor.py
@@ -2,10 +2,11 @@
 # Distributed under the terms of the GNU General Public License v2
 
 import errno
+import shlex
 
 from _emerge.CompositeTask import CompositeTask
 from _emerge.SpawnProcess import SpawnProcess
-from portage import os, _shell_quote, _unicode_encode
+from portage import os, _unicode_encode
 from portage.const import BASH_BINARY
 
 
@@ -31,7 +32,7 @@ class BinpkgEnvExtractor(CompositeTask):
     def _start(self):
         saved_env_path = self._get_saved_env_path()
         dest_env_path = self._get_dest_env_path()
-        shell_cmd = f"${{PORTAGE_BUNZIP2_COMMAND:-${{PORTAGE_BZIP2_COMMAND}} -d}} -c -- {_shell_quote(saved_env_path)} > {_shell_quote(dest_env_path)}"
+        shell_cmd = f"${{PORTAGE_BUNZIP2_COMMAND:-${{PORTAGE_BZIP2_COMMAND}} -d}} -c -- {shlex.quote(saved_env_path)} > {shlex.quote(dest_env_path)}"
 
         logfile = None
         if self.settings.get("PORTAGE_BACKGROUND") != "subprocess":

diff --git a/lib/_emerge/BinpkgExtractorAsync.py b/lib/_emerge/BinpkgExtractorAsync.py
index d1b6374c08..3a31154120 100644
--- a/lib/_emerge/BinpkgExtractorAsync.py
+++ b/lib/_emerge/BinpkgExtractorAsync.py
@@ -45,7 +45,7 @@ class BinpkgExtractorAsync(SpawnProcess):
             if b"--xattrs" in output:
                 tar_options = ["--xattrs", "--xattrs-include='*'"]
                 for x in shlex.split(self.env.get("PORTAGE_XATTR_EXCLUDE", "")):
-                    tar_options.append(portage._shell_quote(f"--xattrs-exclude={x}"))
+                    tar_options.append(shlex.quote(f"--xattrs-exclude={x}"))
                 tar_options = " ".join(tar_options)
 
         decomp = _compressors.get(compression_probe(self.pkg_path))
@@ -119,9 +119,9 @@ class BinpkgExtractorAsync(SpawnProcess):
             "-c",
             textwrap.dedent(
                 f"""
-                    cmd0=(head -c {pkg_xpak.filestat.st_size - pkg_xpak.xpaksize} -- {portage._shell_quote(self.pkg_path)})
+                    cmd0=(head -c {pkg_xpak.filestat.st_size - pkg_xpak.xpaksize} -- {shlex.quote(self.pkg_path)})
                     cmd1=({decomp_cmd})
-                    cmd2=(tar -xp {tar_options} -C {portage._shell_quote(self.image_dir)} -f -);
+                    cmd2=(tar -xp {tar_options} -C {shlex.quote(self.image_dir)} -f -);
                 """
                 """
                     "${cmd0[@]}" | "${cmd1[@]}" | "${cmd2[@]}";

diff --git a/lib/_emerge/MiscFunctionsProcess.py b/lib/_emerge/MiscFunctionsProcess.py
index 16fd082229..76dfbfe0d2 100644
--- a/lib/_emerge/MiscFunctionsProcess.py
+++ b/lib/_emerge/MiscFunctionsProcess.py
@@ -1,6 +1,8 @@
 # Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+import shlex
+
 from _emerge.AbstractEbuildProcess import AbstractEbuildProcess
 import portage
 
@@ -22,7 +24,7 @@ class MiscFunctionsProcess(AbstractEbuildProcess):
             portage_bin_path, os.path.basename(portage.const.MISC_SH_BINARY)
         )
 
-        self.args = [portage._shell_quote(misc_sh_binary)] + self.commands
+        self.args = [shlex.quote(misc_sh_binary)] + self.commands
         if (
             self.logfile is None
             and self.settings.get("PORTAGE_BACKGROUND") != "subprocess"

diff --git a/lib/_emerge/PackagePhase.py b/lib/_emerge/PackagePhase.py
index 64e369812d..b87ae5dc00 100644
--- a/lib/_emerge/PackagePhase.py
+++ b/lib/_emerge/PackagePhase.py
@@ -1,6 +1,7 @@
 # Copyright 2018 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+import shlex
 
 from _emerge.CompositeTask import CompositeTask
 from _emerge.EbuildProcess import EbuildProcess
@@ -60,7 +61,7 @@ class PackagePhase(CompositeTask):
                             "rm -rf {PROOT}; "
                             'cp -pPR $(cp --help | grep -q -- "^[[:space:]]*-l," && echo -l)'
                             ' "${{D}}" {PROOT}'
-                        ).format(PROOT=portage._shell_quote(self._proot)),
+                        ).format(PROOT=shlex.quote(self._proot)),
                     ],
                     background=self.background,
                     env=self.settings.environ(),

diff --git a/lib/portage/__init__.py b/lib/portage/__init__.py
index 0a4e89a4dd..91b16f87a3 100644
--- a/lib/portage/__init__.py
+++ b/lib/portage/__init__.py
@@ -445,23 +445,6 @@ def _get_stdin():
     return sys.stdin
 
 
-_shell_quote_re = re.compile(r"[\s><=*\\\"'$`;&|(){}\[\]#!~?]")
-
-
-def _shell_quote(s):
-    """
-    Quote a string in double-quotes and use backslashes to
-    escape any backslashes, double-quotes, dollar signs, or
-    backquotes in the string.
-    """
-    if _shell_quote_re.search(s) is None:
-        return s
-    for letter in r"\"$`":
-        if letter in s:
-            s = s.replace(letter, rf"\{letter}")
-    return f'"{s}"'
-
-
 bsd_chflags = None
 
 if platform.system() in ("FreeBSD",):

diff --git a/lib/portage/eclass_cache.py b/lib/portage/eclass_cache.py
index c4c7831684..eaeeda4506 100644
--- a/lib/portage/eclass_cache.py
+++ b/lib/portage/eclass_cache.py
@@ -4,6 +4,7 @@
 
 __all__ = ["cache"]
 
+import shlex
 import stat
 import operator
 import warnings
@@ -12,7 +13,6 @@ import errno
 from portage.exception import FileNotFound, PermissionDenied
 from portage import os
 from portage import checksum
-from portage import _shell_quote
 
 
 class hashed_path:
@@ -175,7 +175,5 @@ class cache:
     @property
     def eclass_locations_string(self):
         if self._eclass_locations_str is None:
-            self._eclass_locations_str = " ".join(
-                _shell_quote(x) for x in reversed(self.porttrees)
-            )
+            self._eclass_locations_str = shlex.join(reversed(self.porttrees))
         return self._eclass_locations_str

diff --git a/lib/portage/package/ebuild/config.py b/lib/portage/package/ebuild/config.py
index 84e8d8637a..c30cde3b0b 100644
--- a/lib/portage/package/ebuild/config.py
+++ b/lib/portage/package/ebuild/config.py
@@ -669,7 +669,7 @@ class config:
                 for ov in portdir_overlay:
                     ov = normalize_path(ov)
                     if isdir_raise_eaccess(ov) or portage._sync_mode:
-                        new_ov.append(portage._shell_quote(ov))
+                        new_ov.append(shlex.quote(ov))
                     else:
                         writemsg(
                             _("!!! Invalid PORTDIR_OVERLAY" " (not a dir): '%s'\n")

diff --git a/lib/portage/package/ebuild/doebuild.py b/lib/portage/package/ebuild/doebuild.py
index 1d257d52db..54831ccdae 100644
--- a/lib/portage/package/ebuild/doebuild.py
+++ b/lib/portage/package/ebuild/doebuild.py
@@ -16,6 +16,7 @@ import re
 import shlex
 import signal
 import stat
+import subprocess
 import sys
 import tempfile
 from textwrap import wrap
@@ -58,7 +59,6 @@ from portage import (
     unmerge,
     _encodings,
     _os_merge,
-    _shell_quote,
     _unicode_decode,
     _unicode_encode,
 )
@@ -233,7 +233,7 @@ def _doebuild_spawn(phase, settings, actionmap=None, **kwargs):
             ebuild_sh_arg = phase
 
         cmd = "{} {}".format(
-            _shell_quote(
+            shlex.quote(
                 os.path.join(
                     settings["PORTAGE_BIN_PATH"], os.path.basename(EBUILD_SH_BINARY)
                 )
@@ -1722,8 +1722,8 @@ def _spawn_actionmap(settings):
         portage_bin_path, os.path.basename(EBUILD_SH_BINARY)
     )
     misc_sh_binary = os.path.join(portage_bin_path, os.path.basename(MISC_SH_BINARY))
-    ebuild_sh = _shell_quote(ebuild_sh_binary) + " %s"
-    misc_sh = _shell_quote(misc_sh_binary) + " __dyn_%s"
+    ebuild_sh = shlex.quote(ebuild_sh_binary) + " %s"
+    misc_sh = shlex.quote(misc_sh_binary) + " __dyn_%s"
 
     # args are for the to spawn function
     actionmap = {
@@ -2613,35 +2613,38 @@ def _post_src_install_write_metadata(settings):
 
 def _preinst_bsdflags(mysettings):
     if bsd_chflags:
-        # Save all the file flags for restoration later.
-        os.system(
-            "mtree -c -p %s -k flags > %s"
-            % (
-                _shell_quote(mysettings["D"]),
-                _shell_quote(os.path.join(mysettings["T"], "bsdflags.mtree")),
-            )
-        )
+        try:
+            # Save all the file flags for restoration later.
+            with open(os.path.join(mysettings["T"], "bsdflags.mtree"), "wb") as outfile:
+                subprocess.run(
+                    ["mtree", "-c", "-p", mysettings["D"], "-k", "flags"],
+                    stdout=outfile,
+                )
 
-        # Remove all the file flags to avoid EPERM errors.
-        os.system(
-            "chflags -R noschg,nouchg,nosappnd,nouappnd %s"
-            % (_shell_quote(mysettings["D"]),)
-        )
-        os.system(
-            f"chflags -R nosunlnk,nouunlnk {_shell_quote(mysettings['D'])} 2>/dev/null"
-        )
+            # Remove all the file flags to avoid EPERM errors.
+            subprocess.run(
+                ["chflags", "-R", "noschg,nouchg,nosappnd,nouappnd", mysettings["D"]]
+            )
+            subprocess.run(
+                ["chflags", "-R", "nosunlnk,nouunlnk", mysettings["D"]],
+                stderr=subprocess.DEVNULL,
+            )
+        except OSError:
+            pass
 
 
 def _postinst_bsdflags(mysettings):
     if bsd_chflags:
-        # Restore all of the flags saved above.
-        os.system(
-            "mtree -e -p %s -U -k flags < %s > /dev/null"
-            % (
-                _shell_quote(mysettings["ROOT"]),
-                _shell_quote(os.path.join(mysettings["T"], "bsdflags.mtree")),
-            )
-        )
+        try:
+            # Restore all of the flags saved above.
+            with open(os.path.join(mysettings["T"], "bsdflags.mtree"), "rb") as infile:
+                subprocess.run(
+                    ["mtree", "-e", "-p", mysettings["ROOT"], "-U", "-k", "flags"],
+                    stdin=infile,
+                    stdout=subprocess.DEVNULL,
+                )
+        except OSError:
+            pass
 
 
 def _post_src_install_uid_fix(mysettings, out):
@@ -2886,8 +2889,8 @@ def _reapply_bsdflags_to_image(mysettings):
         os.system(
             "mtree -e -p %s -U -k flags < %s > /dev/null"
             % (
-                _shell_quote(mysettings["D"]),
-                _shell_quote(os.path.join(mysettings["T"], "bsdflags.mtree")),
+                shlex.quote(mysettings["D"]),
+                shlex.quote(os.path.join(mysettings["T"], "bsdflags.mtree")),
             )
         )
 

diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py
index 0947f45aa3..0ea5f57a92 100644
--- a/lib/portage/package/ebuild/fetch.py
+++ b/lib/portage/package/ebuild/fetch.py
@@ -40,7 +40,6 @@ from portage import (
     shutil,
     _encodings,
     _movefile,
-    _shell_quote,
     _unicode_encode,
 )
 from portage.checksum import (
@@ -235,7 +234,7 @@ async def _userpriv_test_write_file(settings, file_path):
     args = [
         BASH_BINARY,
         "-c",
-        _userpriv_test_write_cmd_script % {"file_path": _shell_quote(file_path)},
+        _userpriv_test_write_cmd_script % {"file_path": shlex.quote(file_path)},
     ]
 
     returncode = await _async_spawn_fetch(settings, args)

diff --git a/lib/portage/sync/modules/cvs/cvs.py b/lib/portage/sync/modules/cvs/cvs.py
index e2e3a38a83..12016546f4 100644
--- a/lib/portage/sync/modules/cvs/cvs.py
+++ b/lib/portage/sync/modules/cvs/cvs.py
@@ -2,6 +2,7 @@
 # Distributed under the terms of the GNU General Public License v2
 
 import logging
+import shlex
 
 import portage
 from portage import os
@@ -34,12 +35,10 @@ class CVSSync(NewBase):
             portage.process.spawn_bash(
                 "cd %s; exec cvs -z0 -d %s co -P -d %s %s"
                 % (
-                    portage._shell_quote(os.path.dirname(self.repo.location)),
-                    portage._shell_quote(cvs_root),
-                    portage._shell_quote(os.path.basename(self.repo.location)),
-                    portage._shell_quote(
-                        self.repo.module_specific_options["sync-cvs-repo"]
-                    ),
+                    shlex.quote(os.path.dirname(self.repo.location)),
+                    shlex.quote(cvs_root),
+                    shlex.quote(os.path.basename(self.repo.location)),
+                    shlex.quote(self.repo.module_specific_options["sync-cvs-repo"]),
                 ),
                 **self.spawn_kwargs,
             )
@@ -62,8 +61,7 @@ class CVSSync(NewBase):
 
         # cvs update
         exitcode = portage.process.spawn_bash(
-            "cd %s; exec cvs -z0 -q update -dP"
-            % (portage._shell_quote(self.repo.location),),
+            f"cd {shlex.quote(self.repo.location)}; exec cvs -z0 -q update -dP",
             **self.spawn_kwargs,
         )
         if exitcode != os.EX_OK:

diff --git a/lib/portage/sync/modules/git/git.py b/lib/portage/sync/modules/git/git.py
index a06ca60a82..b97e5c139c 100644
--- a/lib/portage/sync/modules/git/git.py
+++ b/lib/portage/sync/modules/git/git.py
@@ -95,15 +95,11 @@ class GitSync(NewBase):
             git_cmd_opts += (
                 f" {self.repo.module_specific_options['sync-git-clone-extra-opts']}"
             )
-        git_cmd = "{} clone{} {} .".format(
-            self.bin_command,
-            git_cmd_opts,
-            portage._shell_quote(sync_uri),
-        )
+        git_cmd = f"{self.bin_command} clone{git_cmd_opts} {shlex.quote(sync_uri)} ."
         writemsg_level(git_cmd + "\n")
 
         exitcode = portage.process.spawn_bash(
-            f"cd {portage._shell_quote(self.repo.location)} ; exec {git_cmd}",
+            f"cd {shlex.quote(self.repo.location)} ; exec {git_cmd}",
             **self.spawn_kwargs,
         )
         if exitcode != os.EX_OK:
@@ -345,7 +341,7 @@ class GitSync(NewBase):
         )
 
         exitcode = portage.process.spawn_bash(
-            f"cd {portage._shell_quote(self.repo.location)} ; exec {git_cmd}",
+            f"cd {shlex.quote(self.repo.location)} ; exec {git_cmd}",
             **self.spawn_kwargs,
         )
 

diff --git a/lib/portage/sync/modules/mercurial/mercurial.py b/lib/portage/sync/modules/mercurial/mercurial.py
index aad8ff94ab..e4a920fa61 100644
--- a/lib/portage/sync/modules/mercurial/mercurial.py
+++ b/lib/portage/sync/modules/mercurial/mercurial.py
@@ -75,11 +75,7 @@ class MercurialSync(NewBase):
                 " %s"
                 % self.repo.module_specific_options["sync-mercurial-clone-extra-opts"]
             )
-        hg_cmd = "{} clone{} {} .".format(
-            self.bin_command,
-            hg_cmd_opts,
-            portage._shell_quote(sync_uri),
-        )
+        hg_cmd = f"{self.bin_command} clone{hg_cmd_opts} {shlex.quote(sync_uri)} ."
         writemsg_level(hg_cmd + "\n")
 
         exitcode = portage.process.spawn(

diff --git a/lib/portage/sync/modules/svn/svn.py b/lib/portage/sync/modules/svn/svn.py
index ec4bdb006a..453e30ff24 100644
--- a/lib/portage/sync/modules/svn/svn.py
+++ b/lib/portage/sync/modules/svn/svn.py
@@ -2,6 +2,7 @@
 # Distributed under the terms of the GNU General Public License v2
 
 import logging
+import shlex
 
 import portage
 from portage import os
@@ -33,14 +34,14 @@ class SVNSync(NewBase):
         exitcode = portage.process.spawn_bash(
             "cd %s; exec svn co %s ."
             % (
-                portage._shell_quote(self.repo.location),
-                portage._shell_quote(svn_root),
+                shlex.quote(self.repo.location),
+                shlex.quote(svn_root),
             ),
             **self.spawn_kwargs,
         )
         if exitcode != os.EX_OK:
             msg = "!!! svn checkout error; exiting."
-            self.logger(self.xterm_titles, msg)
+            selflogger(self.xterm_titles, msg)
             writemsg_level(msg + "\n", noiselevel=-1, level=logging.ERROR)
         return (exitcode, False)
 
@@ -59,7 +60,7 @@ class SVNSync(NewBase):
 
         # svn update
         exitcode = portage.process.spawn_bash(
-            f"cd {portage._shell_quote(self.repo.location)}; exec svn update",
+            f"cd {shlex.quote(self.repo.location)}; exec svn update",
             **self.spawn_kwargs,
         )
         if exitcode != os.EX_OK:
@@ -77,7 +78,7 @@ class SVNSync(NewBase):
         @rtype: (int, bool)
         """
         exitcode = portage.process.spawn_bash(
-            f"cd {portage._shell_quote(self.repo.location)}; exec svn upgrade",
+            f"cd {shlex.quote(self.repo.location)}; exec svn upgrade",
             **self.spawn_kwargs,
         )
         if exitcode != os.EX_OK:

diff --git a/lib/portage/tests/dbapi/test_portdb_cache.py b/lib/portage/tests/dbapi/test_portdb_cache.py
index c24a4f2098..da72d864ed 100644
--- a/lib/portage/tests/dbapi/test_portdb_cache.py
+++ b/lib/portage/tests/dbapi/test_portdb_cache.py
@@ -1,6 +1,7 @@
 # Copyright 2012-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
+import shlex
 import shutil
 import subprocess
 import sys
@@ -107,7 +108,7 @@ class PortdbCacheTestCase(TestCase):
                 "echo %s > %s"
                 % tuple(
                     map(
-                        portage._shell_quote,
+                        shlex.quote,
                         (
                             "cache-formats = md5-dict pms",
                             layout_conf_path,
@@ -146,7 +147,7 @@ class PortdbCacheTestCase(TestCase):
                 "echo %s > %s"
                 % tuple(
                     map(
-                        portage._shell_quote,
+                        shlex.quote,
                         (
                             "cache-formats = pms md5-dict",
                             layout_conf_path,
@@ -188,7 +189,7 @@ class PortdbCacheTestCase(TestCase):
             ),
             # Test auto-detection and preference for md5-cache when both
             # cache formats are available but layout.conf is absent.
-            (BASH_BINARY, "-c", f"rm {portage._shell_quote(layout_conf_path)}"),
+            (BASH_BINARY, "-c", f"rm {shlex.quote(layout_conf_path)}"),
             python_cmd
             + (
                 textwrap.dedent(

diff --git a/lib/portage/tests/ebuild/meson.build b/lib/portage/tests/ebuild/meson.build
index 0c4407c70d..6ef546f514 100644
--- a/lib/portage/tests/ebuild/meson.build
+++ b/lib/portage/tests/ebuild/meson.build
@@ -6,7 +6,6 @@ py.install_sources(
         'test_doebuild_spawn.py',
         'test_fetch.py',
         'test_ipc_daemon.py',
-        'test_shell_quote.py',
         'test_spawn.py',
         'test_use_expand_incremental.py',
         '__init__.py',

diff --git a/lib/portage/tests/ebuild/test_doebuild_spawn.py b/lib/portage/tests/ebuild/test_doebuild_spawn.py
index cac844f8fb..52635f86ea 100644
--- a/lib/portage/tests/ebuild/test_doebuild_spawn.py
+++ b/lib/portage/tests/ebuild/test_doebuild_spawn.py
@@ -1,11 +1,11 @@
 # Copyright 2010-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
+import shlex
 import textwrap
 
 from portage import os
 from portage import _python_interpreter
-from portage import _shell_quote
 from portage.const import EBUILD_SH_BINARY
 from portage.package.ebuild.config import config
 from portage.package.ebuild.doebuild import spawn as doebuild_spawn
@@ -95,7 +95,7 @@ class DoebuildSpawnTestCase(TestCase):
                 rval = doebuild_spawn(
                     "%s %s"
                     % (
-                        _shell_quote(
+                        shlex.quote(
                             os.path.join(
                                 settings["PORTAGE_BIN_PATH"],
                                 os.path.basename(EBUILD_SH_BINARY),

diff --git a/lib/portage/tests/ebuild/test_shell_quote.py b/lib/portage/tests/ebuild/test_shell_quote.py
deleted file mode 100644
index 885ff34b9e..0000000000
--- a/lib/portage/tests/ebuild/test_shell_quote.py
+++ /dev/null
@@ -1,106 +0,0 @@
-# Copyright 2021 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-
-from portage import _shell_quote
-from portage.tests import TestCase
-
-
-class ShellQuoteTestCase(TestCase):
-    def testShellQuote(self):
-        test_data = [
-            # String contains no special characters, should be preserved.
-            ("abc", "abc"),
-            # String contains whitespace, should be double-quoted to prevent word splitting.
-            ("abc xyz", '"abc xyz"'),
-            ("abc  xyz", '"abc  xyz"'),
-            (" abcxyz ", '" abcxyz "'),
-            ("abc\txyz", '"abc\txyz"'),
-            ("abc\t\txyz", '"abc\t\txyz"'),
-            ("\tabcxyz\t", '"\tabcxyz\t"'),
-            ("abc\nxyz", '"abc\nxyz"'),
-            ("abc\n\nxyz", '"abc\n\nxyz"'),
-            ("\nabcxyz\n", '"\nabcxyz\n"'),
-            # String contains > or <, should be double-quoted to prevent redirection.
-            ("abc>xyz", '"abc>xyz"'),
-            ("abc>>xyz", '"abc>>xyz"'),
-            (">abcxyz>", '">abcxyz>"'),
-            ("abc<xyz", '"abc<xyz"'),
-            ("abc<<xyz", '"abc<<xyz"'),
-            ("<abcxyz<", '"<abcxyz<"'),
-            # String contains =, should be double-quoted to prevent assignment.
-            ("abc=xyz", '"abc=xyz"'),
-            ("abc==xyz", '"abc==xyz"'),
-            ("=abcxyz=", '"=abcxyz="'),
-            # String contains *, should be double-quoted to prevent globbing.
-            ("abc*xyz", '"abc*xyz"'),
-            ("abc**xyz", '"abc**xyz"'),
-            ("*abcxyz*", '"*abcxyz*"'),
-            # String contains $, should be escaped to prevent parameter expansion.
-            # Also double-quoted, though not strictly needed.
-            ("abc$xyz", '"abc\\$xyz"'),
-            ("abc$$xyz", '"abc\\$\\$xyz"'),
-            ("$abcxyz$", '"\\$abcxyz\\$"'),
-            # String contains `, should be escaped to prevent command substitution.
-            # Also double-quoted, though not strictly needed.
-            ("abc`xyz", '"abc\\`xyz"'),
-            ("abc``xyz", '"abc\\`\\`xyz"'),
-            ("`abc`", '"\\`abc\\`"'),
-            # String contains \, should be escaped to prevent it from escaping
-            # the next character. Also double-quoted, though not strictly needed.
-            ("abc\\xyz", '"abc\\\\xyz"'),
-            ("abc\\\\xyz", '"abc\\\\\\\\xyz"'),
-            ("\\abcxyz\\", '"\\\\abcxyz\\\\"'),
-            # String contains ", should be escaped to prevent it from unexpectedly
-            # ending a previous double-quote or starting a new double-quote. Also
-            # double-quoted, though not strictly needed.
-            ('abc"xyz', '"abc\\"xyz"'),
-            ('abc""xyz', '"abc\\"\\"xyz"'),
-            ('"abcxyz"', '"\\"abcxyz\\""'),
-            # String contains ', should be double-quoted to prevent it from unexpectedly
-            # ending a previous single-quote or starting a new single-quote.
-            ("abc'xyz", '"abc\'xyz"'),
-            ("abc''xyz", "\"abc''xyz\""),
-            ("'abcxyz'", "\"'abcxyz'\""),
-            # String contains ;, should be double-quoted to prevent command separation.
-            ("abc;xyz", '"abc;xyz"'),
-            ("abc;;xyz", '"abc;;xyz"'),
-            (";abcxyz;", '";abcxyz;"'),
-            # String contains &, should be double-quoted to prevent job control.
-            ("abc&xyz", '"abc&xyz"'),
-            ("abc&&xyz", '"abc&&xyz"'),
-            ("&abcxyz&", '"&abcxyz&"'),
-            # String contains |, should be double-quoted to prevent piping.
-            ("abc|xyz", '"abc|xyz"'),
-            ("abc||xyz", '"abc||xyz"'),
-            ("|abcxyz|", '"|abcxyz|"'),
-            # String contains (), should be double-quoted to prevent
-            # command group / array initialization.
-            ("abc()xyz", '"abc()xyz"'),
-            ("abc(())xyz", '"abc(())xyz"'),
-            ("((abcxyz))", '"((abcxyz))"'),
-            # String contains {}. Parameter expansion of the form ${} is already
-            # rendered safe by escaping the $, but {} could also occur on its own,
-            # for example in a brace expansion such as filename.{ext1,ext2},
-            # so the string should be double-quoted.
-            ("abc{}xyz", '"abc{}xyz"'),
-            ("abc{{}}xyz", '"abc{{}}xyz"'),
-            ("{{abcxyz}}", '"{{abcxyz}}"'),
-            # String contains [], should be double-quoted to prevent testing
-            ("abc[]xyz", '"abc[]xyz"'),
-            ("abc[[]]xyz", '"abc[[]]xyz"'),
-            ("[[abcxyz]]", '"[[abcxyz]]"'),
-            # String contains #, should be double-quoted to prevent comment.
-            ("#abc", '"#abc"'),
-            # String contains !, should be double-quoted to prevent e.g. history substitution.
-            ("!abc", '"!abc"'),
-            # String contains ~, should be double-quoted to prevent home directory expansion.
-            ("~abc", '"~abc"'),
-            # String contains ?, should be double-quoted to prevent globbing.
-            ("abc?xyz", '"abc?xyz"'),
-            ("abc??xyz", '"abc??xyz"'),
-            ("?abcxyz?", '"?abcxyz?"'),
-        ]
-
-        for data, expected_result in test_data:
-            result = _shell_quote(data)
-            self.assertEqual(result, expected_result)

diff --git a/lib/portage/tests/emerge/test_emerge_slot_abi.py b/lib/portage/tests/emerge/test_emerge_slot_abi.py
index c1a8fe8946..406676809e 100644
--- a/lib/portage/tests/emerge/test_emerge_slot_abi.py
+++ b/lib/portage/tests/emerge/test_emerge_slot_abi.py
@@ -1,6 +1,7 @@
 # Copyright 2012-2019, 2023 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
+import shlex
 import subprocess
 import sys
 
@@ -86,7 +87,7 @@ class SlotAbiEmergeTestCase(TestCase):
                 "echo %s >> %s"
                 % tuple(
                     map(
-                        portage._shell_quote,
+                        shlex.quote,
                         (
                             ">=dev-libs/glib-2.32",
                             package_mask_path,

diff --git a/lib/portage/tests/sync/test_sync_local.py b/lib/portage/tests/sync/test_sync_local.py
index 284c117777..84e64ad2b5 100644
--- a/lib/portage/tests/sync/test_sync_local.py
+++ b/lib/portage/tests/sync/test_sync_local.py
@@ -3,12 +3,13 @@
 
 import datetime
 import json
+import shlex
 import subprocess
 import sys
 import textwrap
 
 import portage
-from portage import os, shutil, _shell_quote
+from portage import os, shutil
 from portage import _unicode_decode
 from portage.const import PORTAGE_PYM_PATH, REPO_REVISIONS, TIMESTAMP_FORMAT
 from portage.process import find_binary
@@ -182,7 +183,7 @@ class SyncLocalTestCase(TestCase):
                     "rsync",
                     None,
                     "sync-rsync-extra-opts = --backup --backup-dir=%s"
-                    % _shell_quote(repo.location + "_back"),
+                    % shlex.quote(repo.location + "_back"),
                 ),
             ),
             (homedir, cmds["emerge"] + ("--sync",)),
@@ -198,7 +199,7 @@ class SyncLocalTestCase(TestCase):
                 lambda: repos_set_conf(
                     "rsync",
                     "sync-rsync-extra-opts = --backup --backup-dir=%s"
-                    % _shell_quote(repo.location + "_back"),
+                    % shlex.quote(repo.location + "_back"),
                 ),
             ),
             (homedir, cmds["emerge"] + ("--sync",)),
@@ -214,9 +215,9 @@ class SyncLocalTestCase(TestCase):
                 lambda: repos_set_conf(
                     "rsync",
                     "sync-rsync-extra-opts = --backup --backup-dir=%s"
-                    % _shell_quote(repo.location + "_back_nowhere"),
+                    % shlex.quote(repo.location + "_back_nowhere"),
                     "sync-rsync-extra-opts = --backup --backup-dir=%s"
-                    % _shell_quote(repo.location + "_back"),
+                    % shlex.quote(repo.location + "_back"),
                 ),
             ),
             (homedir, cmds["emerge"] + ("--sync",)),
@@ -232,7 +233,7 @@ class SyncLocalTestCase(TestCase):
                 lambda: repos_set_conf(
                     "rsync",
                     "sync-rsync-extra-opts = --backup --backup-dir=%s"
-                    % _shell_quote(repo.location + "_back_nowhere"),
+                    % shlex.quote(repo.location + "_back_nowhere"),
                     "sync-rsync-extra-opts = ",
                 ),
             ),


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-01-11 22:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-11 22:50 [gentoo-commits] proj/portage:master commit in: lib/_emerge/, lib/portage/sync/modules/cvs/, lib/portage/tests/ebuild/, Mike Gilbert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox