Skip to content

Commit 21a2a77

Browse files
committed
Add constant for /etc/pacman.conf
1 parent 41858db commit 21a2a77

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed

archinstall/lib/general/general_menu.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from enum import Enum
2-
from pathlib import Path
32

43
from archinstall.lib.locale.utils import list_timezones
54
from archinstall.lib.menu.helpers import Confirmation, Input, Selection
65
from archinstall.lib.output import warn
6+
from archinstall.lib.pathnames import PACMAN_CONF
77
from archinstall.lib.translationhandler import Language, tr
88
from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup
99
from archinstall.tui.ui.result import ResultType
@@ -162,11 +162,10 @@ def validator(s: str) -> str | None:
162162
case ResultType.Selection:
163163
downloads = int(result.get_value())
164164

165-
pacman_conf_path = Path('/etc/pacman.conf')
166-
with pacman_conf_path.open() as f: # noqa: ASYNC230
165+
with PACMAN_CONF.open() as f:
167166
pacman_conf = f.read().split('\n')
168167

169-
with pacman_conf_path.open('w') as fwrite: # noqa: ASYNC230
168+
with PACMAN_CONF.open('w') as fwrite:
170169
for line in pacman_conf:
171170
if 'ParallelDownloads' in line:
172171
fwrite.write(f'ParallelDownloads = {downloads}\n')

archinstall/lib/installer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from archinstall.lib.packages.packages import installed_package
5656
from archinstall.lib.pacman.config import PacmanConfig
5757
from archinstall.lib.pacman.pacman import Pacman
58+
from archinstall.lib.pathnames import PACMAN_CONF
5859
from archinstall.lib.plugins import plugins
5960
from archinstall.lib.translationhandler import tr
6061

@@ -570,7 +571,7 @@ def set_mirrors(
570571

571572
root = self.target if on_target else Path('/')
572573
mirrorlist_config = root / 'etc/pacman.d/mirrorlist'
573-
pacman_config = root / 'etc/pacman.conf'
574+
pacman_config = root / PACMAN_CONF.relative_to_root()
574575

575576
repositories_config = mirror_config.repositories_config()
576577
if repositories_config:

archinstall/lib/linux_path.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pathlib import Path
2+
from typing import Self
3+
4+
5+
class LPath(Path):
6+
@classmethod
7+
def fs_root(cls) -> Self:
8+
return cls('/')
9+
10+
def relative_to_root(self) -> Self:
11+
return self.relative_to(self.fs_root())

archinstall/lib/pacman/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
from shutil import copy2
44

55
from archinstall.lib.models.packages import Repository
6+
from archinstall.lib.pathnames import PACMAN_CONF
67

78

89
class PacmanConfig:
910
def __init__(self, target: Path | None):
10-
self._config_path = Path('/etc') / 'pacman.conf'
1111
self._config_remote_path: Path | None = None
1212

1313
if target:
14-
self._config_remote_path = target / 'etc' / 'pacman.conf'
14+
self._config_remote_path = target / PACMAN_CONF.relative_to_root()
1515

1616
self._repositories: list[Repository] = []
1717

@@ -32,7 +32,7 @@ def apply(self) -> None:
3232
else:
3333
repos_to_enable.append(repo.value)
3434

35-
content = self._config_path.read_text().splitlines(keepends=True)
35+
content = PACMAN_CONF.read_text().splitlines(keepends=True)
3636

3737
for row, line in enumerate(content):
3838
# Check if this is a commented repository section that needs to be enabled
@@ -47,9 +47,9 @@ def apply(self) -> None:
4747
content[row + 1] = re.sub(r'^#\s*', '', content[row + 1])
4848

4949
# Write the modified content back to the file
50-
with open(self._config_path, 'w') as f:
50+
with PACMAN_CONF.open('w') as f:
5151
f.writelines(content)
5252

5353
def persist(self) -> None:
5454
if self._repositories and self._config_remote_path:
55-
copy2(self._config_path, self._config_remote_path)
55+
copy2(PACMAN_CONF, self._config_remote_path)

archinstall/lib/pacman/pacman.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from archinstall.lib.command import SysCommand
77
from archinstall.lib.exceptions import RequirementError
88
from archinstall.lib.output import error, info, warn
9+
from archinstall.lib.pathnames import PACMAN_CONF
910
from archinstall.lib.plugins import plugins
1011
from archinstall.lib.translationhandler import tr
1112

@@ -77,6 +78,6 @@ def strap(self, packages: str | list[str]) -> None:
7778
'Could not strap in packages',
7879
'Pacstrap failed. See /var/log/archinstall/install.log or above message for error details',
7980
SysCommand,
80-
f'pacstrap -C /etc/pacman.conf -K {self.target} {" ".join(packages)} --noconfirm --needed',
81+
f'pacstrap -C {PACMAN_CONF} -K {self.target} {" ".join(packages)} --noconfirm --needed',
8182
peek_output=True,
8283
)

archinstall/lib/pathnames.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from typing import Final
2+
3+
from archinstall.lib.linux_path import LPath
4+
5+
PACMAN_CONF: Final = LPath('/etc/pacman.conf')

0 commit comments

Comments
 (0)