From b00b6901fe2f1e832ad38a9ca6cfef3c7c2ef831 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 16 May 2021 13:35:36 +0200 Subject: mmdebstrap: allow a PurePath for chdir in priv_drop --- mdbp/mmdebstrap.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'mdbp/mmdebstrap.py') diff --git a/mdbp/mmdebstrap.py b/mdbp/mmdebstrap.py index c5139b5..de855f6 100644 --- a/mdbp/mmdebstrap.py +++ b/mdbp/mmdebstrap.py @@ -15,7 +15,7 @@ from .common import buildjson, compute_env, get_dsc, get_dsc_files, \ # pylint: disable=W0102 # as we do not modify env def priv_drop(cmd: typing.List[str], *, chroot: bool = False, - chdir: typing.Optional[str] = None, + chdir: typing.Union[None, str, pathlib.PurePath] = None, setuid: typing.Optional[str] = None, privnet: bool = False, env: typing.Dict[str, str] = {}) -> str: @@ -31,7 +31,7 @@ def priv_drop(cmd: typing.List[str], *, chroot: bool = False, if chdir or env: envcmd = ["env"] if chdir: - envcmd.extend(["--chdir", chdir]) + envcmd.extend(["--chdir", str(chdir)]) envcmd.extend(map("%s=%s".__mod__, env.items())) cmd = envcmd + cmd cmdstring = "" @@ -105,17 +105,16 @@ def main() -> None: script.write("%s\n" % priv_drop( ["dpkg-source", "--no-check", "--extract", dscpath.name, buildpath.name], - setuid="build", chroot=True, chdir=str(buildpath.parent))) + setuid="build", chroot=True, chdir=buildpath.parent)) script.write("%s\n" % priv_drop(["rm"] + [f.name for f in dscfiles], - chroot=True, - chdir=str(buildpath.parent))) + chroot=True, chdir=buildpath.parent)) cmd = ["dpkg-buildpackage", "-uc", "--host-arch=" + hostarch, "--build=" + build.get("type", "binary")] cmd.extend(profile_option(build, "--build-profiles=")) script.write("%s\n" % priv_drop( cmd, chroot=True, setuid="build", privnet=not build.get("network") in ("enable", "try-enable"), - chdir=str(buildpath), env=compute_env(build))) + chdir=buildpath, env=compute_env(build))) script.write("%s\n" % priv_drop(["rm", "-R", str(buildpath)], chroot=True)) if build.get("lintian", {}).get("run"): @@ -125,7 +124,7 @@ def main() -> None: (priv_drop(["apt-get", "install", "--yes", "lintian"], chroot=True), priv_drop(cmd, chroot=True, setuid="build", - chdir=str(buildpath.parent)))) + chdir=buildpath.parent))) # Only close the file object, script.close would delete it. # Unfortunatly, mypy doesn't grok the indirection and thinks that # script already is the file. -- cgit v1.2.3