Fix enabling of testing repositories (#2340)

This commit is contained in:
codefiles 2024-03-07 08:41:25 -05:00 committed by GitHub
parent b39e3dc886
commit 9b1fd2e44f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 9 deletions

View File

@ -661,8 +661,6 @@ class Installer:
if testing: if testing:
info("The testing flag is set. This system will be installed with testing repositories enabled.") info("The testing flag is set. This system will be installed with testing repositories enabled.")
pacman_conf.enable(pacman.Repo.Testing) pacman_conf.enable(pacman.Repo.Testing)
if multilib:
pacman_conf.enable(pacman.Repo.MultilibTesting)
else: else:
info("The testing flag is not set. This system will be installed without testing repositories enabled.") info("The testing flag is not set. This system will be installed without testing repositories enabled.")

View File

@ -10,24 +10,35 @@ class Config:
def __init__(self, target: Path): def __init__(self, target: Path):
self.path = Path("/etc") / "pacman.conf" self.path = Path("/etc") / "pacman.conf"
self.chroot_path = target / "etc" / "pacman.conf" self.chroot_path = target / "etc" / "pacman.conf"
self.patterns: List[re.Pattern] = [] self.repos: List[Repo] = []
def enable(self, repo: Repo): def enable(self, repo: Repo):
self.patterns.append(re.compile(r"^#\s*\[{}\]$".format(repo.value))) self.repos.append(repo)
def apply(self): def apply(self):
if not self.patterns: if not self.repos:
return return
if Repo.Testing in self.repos:
if Repo.Multilib in self.repos:
repos_pattern = f'({Repo.Multilib.value}|.+-{Repo.Testing.value})'
else:
repos_pattern = f'(?!{Repo.Multilib.value}).+-{Repo.Testing.value}'
else:
repos_pattern = Repo.Multilib.value
pattern = re.compile(rf"^#\s*\[{repos_pattern}\]$")
lines = iter(self.path.read_text().splitlines(keepends=True)) lines = iter(self.path.read_text().splitlines(keepends=True))
with open(self.path, 'w') as f: with open(self.path, 'w') as f:
for line in lines: for line in lines:
if any(pattern.match(line) for pattern in self.patterns): if pattern.match(line):
# Uncomment this line and the next. # Uncomment this line and the next.
f.write(line.lstrip('#')) f.write(line.lstrip('#'))
f.write(next(lines).lstrip('#')) f.write(next(lines).lstrip('#'))
else: else:
f.write(line) f.write(line)
def persist(self): def persist(self):
if self.patterns: if self.repos:
copy2(self.path, self.chroot_path) copy2(self.path, self.chroot_path)

View File

@ -3,4 +3,3 @@ from enum import Enum
class Repo(Enum): class Repo(Enum):
Multilib = "multilib" Multilib = "multilib"
Testing = "testing" Testing = "testing"
MultilibTesting = "multilib-testing"