diff --git a/src/decman/app.py b/src/decman/app.py index b93c841..8f182a1 100644 --- a/src/decman/app.py +++ b/src/decman/app.py @@ -35,9 +35,11 @@ def main(): help="print what would happen as a result of running decman", ) parser.add_argument("--debug", action="store_true", default=False, help="show debug output") - parser.add_argument("--skip", nargs="*", type=str, help="skip the following execution steps") parser.add_argument( - "--only", nargs="*", type=str, help="run only the following execution steps" + "--skip", nargs="*", type=str, default=[], help="skip the following execution steps" + ) + parser.add_argument( + "--only", nargs="*", type=str, default=[], help="run only the following execution steps" ) parser.add_argument( "--no-hooks", @@ -178,6 +180,8 @@ def run_decman(store: _store.Store, args: argparse.Namespace) -> bool: If running any command fails. """ + output.print_debug(f"Available plugins: {' '.join(decman.plugins.keys())}") + store.ensure("enabled_modules", []) store.ensure("module_on_disable_scripts", {}) diff --git a/src/decman/plugins/aur/package.py b/src/decman/plugins/aur/package.py index 3d0a0e9..af5b511 100644 --- a/src/decman/plugins/aur/package.py +++ b/src/decman/plugins/aur/package.py @@ -2,6 +2,7 @@ import dataclasses import os import pathlib import re +import shutil import tempfile import requests # type: ignore @@ -276,35 +277,63 @@ class CustomPackage: self.git_url, self.pkgbuild_directory, f"No PKGBUILD found in '{path}'." ) - return self._run_makepkg_printsrcinfo(path, commands) + try: + with tempfile.TemporaryDirectory(prefix="decman-pkgbuild-") as tmpdir: + tmp_path = pathlib.Path(tmpdir) + # Allow the user 'nobody' to read here + os.chmod(tmpdir, 0o755) + shutil.copy(path / "PKGBUILD", tmp_path / "PKGBUILD") + os.chmod(tmp_path / "PKGBUILD", 0o644) + + return self._run_makepkg_printsrcinfo(tmp_path, commands) + except OSError as error: + raise PKGBUILDParseError( + self.git_url, + self.pkgbuild_directory, + "Failed to create temporary directory for the PKGBUILD.", + ) from error def _srcinfo_from_git(self, commands: AurCommands) -> str: assert self.git_url is not None, "This will not get called if git_url is unset." - with tempfile.TemporaryDirectory(prefix="decman-pkgbuild-") as tmpdir: - tmp_path = pathlib.Path(tmpdir) - try: - cmd = commands.git_clone(self.git_url, tmpdir) - command.check_run_result(cmd, command.run(cmd)) - except errors.CommandFailedError as error: - raise PKGBUILDParseError( - self.git_url, self.pkgbuild_directory, "Failed to clone PKGBUILD repository." - ) from error + try: + with tempfile.TemporaryDirectory(prefix="decman-pkgbuild-") as tmpdir: + tmp_path = pathlib.Path(tmpdir) + # Allow the user 'nobody' to write here + os.chmod(tmpdir, 0o777) + try: + cmd = commands.git_clone(self.git_url, tmpdir) + # Use the user nobody, since that will be used later to generate SRCINFO + command.check_run_result(cmd, command.run(cmd, user="nobody")) + except errors.CommandFailedError as error: + raise PKGBUILDParseError( + self.git_url, + self.pkgbuild_directory, + "Failed to clone PKGBUILD repository.", + ) from error - if not (tmp_path / "PKGBUILD").exists(): - raise PKGBUILDParseError( - self.git_url, - self.pkgbuild_directory, - f"Cloned repository '{self.git_url}' does not contain a PKGBUILD.", - ) + if not (tmp_path / "PKGBUILD").exists(): + raise PKGBUILDParseError( + self.git_url, + self.pkgbuild_directory, + f"Cloned repository '{self.git_url}' does not contain a PKGBUILD.", + ) - return self._run_makepkg_printsrcinfo(tmp_path, commands) + return self._run_makepkg_printsrcinfo(tmp_path, commands) + except OSError as error: + raise PKGBUILDParseError( + self.git_url, + self.pkgbuild_directory, + "Failed to create temporary directory for the PKGBUILD.", + ) from error def _run_makepkg_printsrcinfo(self, path: pathlib.Path, commands: AurCommands) -> str: orig_wd = os.getcwd() try: os.chdir(path) cmd = commands.print_srcinfo() - _, srcinfo = command.check_run_result(cmd, command.run(cmd)) + # No need to use the makepkg_user config option here. + # For just printing the SRCINFO, hardcoded 'nobody' works + _, srcinfo = command.check_run_result(cmd, command.run(cmd, user="nobody")) except errors.CommandFailedError as error: raise PKGBUILDParseError( self.git_url, self.pkgbuild_directory, "Failed to generate SRCINFO using makepkg."