1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-13 03:19:47 +03:00

core: pkgrepo: support arbitrarily named pmaports directories (MR 2470)

There was an oversight when this API was originally created and it
implicitly assumed that the pmaports repository was always named
"pmaports". This unfortunately broke some peoples workflows.

Introduce a new "pkgrepo_name()" function and adjust the codebase to use
it, as well as adjusting pkgrepo internally to special case the
"pmaports" repo so that it's always named pmaports no matter what the
directory itself is named.

This is probably more complexity than we should be dealing with here, we
should probably create a new type to encode this behaviour.

Fixes: #2412
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-11-02 16:01:46 +01:00 committed by Oliver Smith
parent 70dc855281
commit a72a60f546
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
5 changed files with 49 additions and 15 deletions

View file

@ -28,21 +28,42 @@ def pkgrepo_paths(skip_extras: bool = False) -> list[Path]:
return out_paths
@Cache()
def pkgrepo_default_path() -> Path:
return pkgrepo_paths(skip_extras=True)[0]
def pkgrepo_names(skip_exras: bool = False) -> list[str]:
"""
Return a list of all the package repository names.
Return a list of all the package repository names. We REQUIRE
that the last repository is "pmaports", though the directory
may be named differently. So we hardcode the name here.
"""
return [aports.name for aports in pkgrepo_paths(skip_exras)]
names = [aports.name for aports in pkgrepo_paths(skip_exras)]
names[-1] = "pmaports"
return names
def pkgrepo_name(path: Path) -> str:
"""
Return the name of the package repository with the given path. This
MUST be used instead of "path.name" as we need special handling
for the pmaports repository.
"""
if path == get_context().config.aports[-1]:
return "pmaports"
return path.name
def pkgrepo_path(name: str) -> Path:
"""
Return the absolute path to the package repository with the given name.
"""
# The pmaports repo is always last, and we hardcode the name.
if name == "pmaports":
return get_context().config.aports[-1]
for aports in pkgrepo_paths():
if aports.name == name:
return aports
@ -56,7 +77,7 @@ def pkgrepo_name_from_subdir(subdir: Path) -> str:
"""
for aports in pkgrepo_paths():
if subdir.is_relative_to(aports):
return aports.name
return pkgrepo_name(aports)
raise RuntimeError(f"aports subdir '{subdir}' not found")
@ -105,14 +126,14 @@ def pkgrepo_iter_package_dirs(skip_extra_repos: bool = False) -> Generator[Path,
if "extra-repos" not in repo.parts and "extra-repos" in pdir.parts:
continue
pkg = os.path.basename(pdir)
if pkg in seen[repo.name]:
if pkg in seen[pkgrepo_name(repo)]:
raise RuntimeError(
f"Package {pkg} found in multiple aports "
"subfolders. Please put it only in one folder."
)
if pkg in [x for li in seen.values() for x in li]:
continue
seen[repo.name].append(pkg)
seen[pkgrepo_name(repo)].append(pkg)
yield pdir