From bde9d9c70db27b116ef4b428bc2a10fd9bfb2bea Mon Sep 17 00:00:00 2001 From: user Date: Thu, 23 Jan 2025 18:10:36 -0500 Subject: [PATCH 1/2] Fix bug in module user systemd unit handling --- src/decman/lib/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/decman/lib/__init__.py b/src/decman/lib/__init__.py index c92bb41..8e2e521 100644 --- a/src/decman/lib/__init__.py +++ b/src/decman/lib/__init__.py @@ -680,11 +680,13 @@ class Source: return result def _all_user_units(self) -> dict[str, set[str]]: - result = {} - result.update(self.systemd_user_units) - for module in self.modules: - if module.enabled: - result.update(module.systemd_user_units()) + result = self.systemd_user_units + for module in [m for m in self.modules if m.enabled]: + module_user_units: dict[str, list[str]] = module.systemd_user_units() + for user in module_user_units.keys(): + if user not in result: + result[user] = set() + result[user].update(module_user_units[user]) return result From e153b8c40036e1b70753abbce0f6c560d6a1529f Mon Sep 17 00:00:00 2001 From: user Date: Thu, 23 Jan 2025 18:37:38 -0500 Subject: [PATCH 2/2] Add test for multiple module user services --- tests/test_source_resolution.py | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/test_source_resolution.py b/tests/test_source_resolution.py index 4084d93..c4c887c 100644 --- a/tests/test_source_resolution.py +++ b/tests/test_source_resolution.py @@ -264,3 +264,49 @@ class TestSource(unittest.TestCase): self.source.packages_to_remove(self.currently_installed_packages), ["p4", "A4", "M_A1", "M_A2"], ) + +class TestModuleUserServices(unittest.TestCase): + + class ModuleWithUserServiceOne(Module): + + def __init__(self): + super().__init__("one", True, "0") + + def systemd_user_units(self) -> dict[str, list[str]]: + return { + "user": ['foo.service'] + } + + class ModuleWithUserServiceTwo(Module): + + def __init__(self): + super().__init__("two", True, "0") + + def systemd_user_units(self) -> dict[str, list[str]]: + return { + "user": ['bar.service'] + } + + def setUp(self) -> None: + self.source = Source( + pacman_packages=set(), + aur_packages=set(), + user_packages=set(), + ignored_packages=set(), + systemd_units=set(), + systemd_user_units={}, + files={}, + directories={}, + modules={ + self.ModuleWithUserServiceOne(), + self.ModuleWithUserServiceTwo() + }, + ) + self.store = Store() + + + def test_user_units_to_enable(self): + self.assertDictEqual( + self.source.user_units_to_enable(self.store), + {"user": ["foo.service", "bar.service"]}, + )