mirror of
https://github.com/kiviktnm/decman.git
synced 2026-09-19 12:08:28 +00:00
Use nobody-user for parsing PKGBUILDs
This commit is contained in:
+6
-2
@@ -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", {})
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import dataclasses
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
import requests # type: ignore
|
||||
@@ -276,18 +277,38 @@ 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."
|
||||
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)
|
||||
command.check_run_result(cmd, command.run(cmd))
|
||||
# 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."
|
||||
self.git_url,
|
||||
self.pkgbuild_directory,
|
||||
"Failed to clone PKGBUILD repository.",
|
||||
) from error
|
||||
|
||||
if not (tmp_path / "PKGBUILD").exists():
|
||||
@@ -298,13 +319,21 @@ class CustomPackage:
|
||||
)
|
||||
|
||||
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."
|
||||
|
||||
Reference in New Issue
Block a user