From d57b9e31e193dbbd62bf4da227f1c2c8737e4df1 Mon Sep 17 00:00:00 2001
From: Caleb Connolly <caleb@postmarketos.org>
Date: Sat, 2 Nov 2024 16:47:20 +0100
Subject: [PATCH] config: init: support --aports too (MR 2470)

We shouldn't overwrite config.aports if the user specified a custom
--aports directory. We only want to do this to update the default if
they're using a custom workdir.

Make the code here less aggressive, and correctly use the last entry in
config.aports as "pmaports" instead of the first.

Fixes: #2386
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
---
 pmb/config/init.py     | 8 +++++---
 pmb/parse/arguments.py | 1 +
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/pmb/config/init.py b/pmb/config/init.py
index 317e92b93..142d03d49 100644
--- a/pmb/config/init.py
+++ b/pmb/config/init.py
@@ -697,11 +697,13 @@ def frontend(args: PmbArgs) -> None:
     # Work folder (needs to be first, so we can create chroots early)
     config = get_context().config
 
+    using_default_pmaports = config.aports[-1].is_relative_to(config.work)
+
     config.work, work_exists = ask_for_work_path(config.work)
 
-    # If the work dir is not the default, reset aports and make
-    # it relative to the work dir
-    if not config.aports[0].is_relative_to(config.work):
+    # If the work dir changed then we need to update the pmaports path
+    # to be relative to the new workdir
+    if using_default_pmaports:
         config.aports = [config.work / "cache_git/pmaports"]
 
     # Update args and save config (so chroots and 'pmbootstrap log' work)
diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py
index 7dfeb716b..c6eecd02e 100644
--- a/pmb/parse/arguments.py
+++ b/pmb/parse/arguments.py
@@ -886,6 +886,7 @@ def get_parser():
     parser.add_argument(
         "-w",
         "--work",
+        type=lambda x: Path(x).absolute(),
         help="folder where all data gets stored (chroots, caches, built packages)",
     )
     parser.add_argument(
-- 
GitLab