Skip to content

Commit 50d6b56

Browse files
committed
refactor(privilege): remove function duplicated in config module
1 parent 4c8e8de commit 50d6b56

9 files changed

+17
-30
lines changed

.coveragerc

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ exclude_lines =
1212
NotImplemented
1313
if __name__ == .__main__.:
1414
if TYPE_CHECKING:
15-
if running_as_root
15+
if RunningAsRoot
1616
if not args.noconfirm
1717
if not self.args.noconfirm
1818
if args.debug

maintenance_scripts/get_global_expressions.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ result=$(
1414
-e TypeVar \
1515
-e namedtuple \
1616
\
17-
-e 'create_logger\(|running_as_root|sudo' \
17+
-e 'create_logger\(|sudo' \
1818
\
1919
-e './maintenance_scripts/find_.*.py.*:.*:' \
2020
-e '.SRCINFO' \

maintenance_scripts/get_non_final_expressions.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ result=$(
1212
-e TypeVar \
1313
-e namedtuple \
1414
\
15-
-e 'create_logger\(|running_as_root|sudo' \
15+
-e 'create_logger\(|sudo' \
1616
\
1717
-e './maintenance_scripts/find_.*.py.*:.*:' \
1818
-e '.SRCINFO' \

pikaur/build.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
BuildDepsLockPath,
1717
PackageCachePath,
1818
PikaurConfig,
19+
UsingDynamicUsers,
1920
)
2021
from .core import (
2122
PIPE,
@@ -56,7 +57,6 @@
5657
from .privilege import (
5758
isolate_root_cmd,
5859
sudo,
59-
using_dynamic_users,
6060
)
6161
from .prompt import (
6262
ask_to_continue,
@@ -995,7 +995,7 @@ def clone_aur_repos(package_names: list[str]) -> dict[str, PackageBuild]:
995995
pool_size: int | None = None
996996
if clone_c := parse_args().aur_clone_concurrency:
997997
pool_size = clone_c
998-
elif using_dynamic_users():
998+
elif UsingDynamicUsers():
999999
pool_size = 1
10001000
exc: CloneError | None = None
10011001
with (

pikaur/install_cli.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .args import parse_args, reconstruct_args
1212
from .aur import AURPackageInfo
1313
from .build import PackageBuild, PkgbuildChanged, clone_aur_repos
14-
from .config import DiffPagerValues, PikaurConfig
14+
from .config import DiffPagerValues, PikaurConfig, UsingDynamicUsers
1515
from .conflicts import find_aur_conflicts
1616
from .core import (
1717
PackageSource,
@@ -61,7 +61,6 @@
6161
from .privilege import (
6262
isolate_root_cmd,
6363
sudo,
64-
using_dynamic_users,
6564
)
6665
from .prompt import (
6766
ask_to_continue,
@@ -830,7 +829,7 @@ def _get_installed_status(self) -> None: # pylint: disable=too-many-branches
830829
# if running as root get sources for dev packages synchronously
831830
# (to prevent race condition in systemd dynamic users)
832831
num_threads: int | None = None
833-
if using_dynamic_users(): # pragma: no cover
832+
if UsingDynamicUsers(): # pragma: no cover
834833
num_threads = 1
835834

836835
# check if pkgs versions already installed

pikaur/main.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@
5151
get_args_to_elevate_pikaur,
5252
isolate_root_cmd,
5353
need_dynamic_users,
54-
running_as_root,
5554
sudo,
56-
using_dynamic_users,
5755
)
5856
from .prompt import NotANumberInputError, get_multiple_numbers_input
5957
from .search_cli import cli_search_packages, search_packages
@@ -254,7 +252,7 @@ def execute_pikaur_operation(
254252
args.positional += add_args
255253
cli_args += add_args
256254
if (
257-
running_as_root()
255+
RunningAsRoot()
258256
and (PikaurConfig().build.DynamicUsers.get_str() == "never" and not args.user_id)
259257
):
260258
print_error(
@@ -266,7 +264,7 @@ def execute_pikaur_operation(
266264
sys.exit(1)
267265
elif (
268266
require_sudo
269-
and not running_as_root()
267+
and not RunningAsRoot()
270268
and (
271269
args.privilege_escalation_target == "pikaur"
272270
or need_dynamic_users()
@@ -376,7 +374,7 @@ def migrate_old_aur_repos_dir() -> None:
376374

377375

378376
def create_dirs() -> None:
379-
if using_dynamic_users():
377+
if UsingDynamicUsers():
380378
# Let systemd-run setup the directories and symlinks
381379
true_cmd = isolate_root_cmd(["true"])
382380
result = spawn(true_cmd)

pikaur/makepkg_config.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from typing import TYPE_CHECKING
66

77
from .args import parse_args
8-
from .config import ConfigRoot, _UserTempRoot
8+
from .config import ConfigRoot, UsingDynamicUsers, _UserTempRoot
99
from .core import open_file
10-
from .privilege import using_dynamic_users
1110

1211
if TYPE_CHECKING:
1312
from typing import Final, TypeVar
@@ -142,7 +141,7 @@ class MakePkgCommand:
142141

143142
@classmethod
144143
def _apply_dynamic_users_workaround(cls) -> None:
145-
if not using_dynamic_users():
144+
if not UsingDynamicUsers():
146145
return
147146
pkgdest = str(get_pkgdest())
148147
if pkgdest and (

pikaur/privilege.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
ConfigPath,
77
PikaurConfig,
88
RunningAsRoot,
9-
UsingDynamicUsers,
109
_UserTempRoot,
1110
)
1211

@@ -28,15 +27,7 @@ def need_dynamic_users() -> bool:
2827
return True
2928
if dynamic_users == "never":
3029
return False
31-
return bool(running_as_root() and dynamic_users == "root")
32-
33-
34-
def using_dynamic_users() -> int:
35-
return UsingDynamicUsers()
36-
37-
38-
def running_as_root() -> int:
39-
return RunningAsRoot()
30+
return bool(RunningAsRoot() and dynamic_users == "root")
4031

4132

4233
def sudo(cmd: list[str], preserve_env: list[str] | None = None) -> list[str]:
@@ -56,7 +47,7 @@ def isolate_root_cmd(
5647
cwd: str | Path | None = None,
5748
env: dict[str, str] | None = None,
5849
) -> list[str]:
59-
if not running_as_root():
50+
if not RunningAsRoot():
6051
return cmd
6152
if isinstance(cwd, str):
6253
cwd = Path(cwd)

pikaur/srcinfo.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import shutil
44
from pathlib import Path
55

6-
from .config import BuildCachePath, CacheRoot
6+
from .config import BuildCachePath, CacheRoot, UsingDynamicUsers
77
from .core import chown_to_current, open_file, spawn
88
from .exceptions import SysExit
99
from .i18n import translate
1010
from .makepkg_config import MakePkgCommand, MakepkgConfig
1111
from .pprint import print_error, print_stderr
12-
from .privilege import isolate_root_cmd, using_dynamic_users
12+
from .privilege import isolate_root_cmd
1313
from .version import VersionMatcher
1414

1515

@@ -127,7 +127,7 @@ def get_version(self) -> str:
127127

128128
def regenerate(self) -> None:
129129
working_directory = self.repo_path
130-
if using_dynamic_users() and not str(self.repo_path).startswith(str(CacheRoot())):
130+
if UsingDynamicUsers() and not str(self.repo_path).startswith(str(CacheRoot())):
131131
working_directory = BuildCachePath() / (
132132
"_info_" + (self.get_value("pkgbase") or "unknown")
133133
)

0 commit comments

Comments
 (0)