mirror of
https://github.com/kiviktnm/decman.git
synced 2026-09-19 12:08:28 +00:00
Update store only after an operation has been done
This commit is contained in:
+14
-13
@@ -619,33 +619,31 @@ class Systemd:
|
|||||||
"""
|
"""
|
||||||
Enables the given units.
|
Enables the given units.
|
||||||
"""
|
"""
|
||||||
self.state.enabled_systemd_units += units
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(conf.commands.enable_units(units), check=True)
|
subprocess.run(conf.commands.enable_units(units), check=True)
|
||||||
except subprocess.CalledProcessError as error:
|
except subprocess.CalledProcessError as error:
|
||||||
raise UserFacingError("Failed to enable systemd units.") from error
|
raise UserFacingError("Failed to enable systemd units.") from error
|
||||||
|
self.state.enabled_systemd_units += units
|
||||||
|
|
||||||
def disable_units(self, units: list[str]):
|
def disable_units(self, units: list[str]):
|
||||||
"""
|
"""
|
||||||
Disables the given units.
|
Disables the given units.
|
||||||
"""
|
"""
|
||||||
for unit in units:
|
|
||||||
try:
|
|
||||||
self.state.enabled_systemd_units.remove(unit)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(conf.commands.disable_units(units), check=True)
|
subprocess.run(conf.commands.disable_units(units), check=True)
|
||||||
except subprocess.CalledProcessError as error:
|
except subprocess.CalledProcessError as error:
|
||||||
raise UserFacingError(
|
raise UserFacingError(
|
||||||
"Failed to disable systemd units.") from error
|
"Failed to disable systemd units.") from error
|
||||||
|
for unit in units:
|
||||||
|
try:
|
||||||
|
self.state.enabled_systemd_units.remove(unit)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
def enable_user_units(self, units: list[str], user: str):
|
def enable_user_units(self, units: list[str], user: str):
|
||||||
"""
|
"""
|
||||||
Enables the given units for the given user.
|
Enables the given units for the given user.
|
||||||
"""
|
"""
|
||||||
for unit in units:
|
|
||||||
self.state.enabled_user_systemd_units.append((user, unit))
|
|
||||||
try:
|
try:
|
||||||
uid = pwd.getpwnam(user).pw_uid
|
uid = pwd.getpwnam(user).pw_uid
|
||||||
gid = pwd.getpwnam(user).pw_gid
|
gid = pwd.getpwnam(user).pw_gid
|
||||||
@@ -661,16 +659,13 @@ class Systemd:
|
|||||||
raise UserFacingError(
|
raise UserFacingError(
|
||||||
f"Failed to enable systemd units because user '{user}' doesn't exist."
|
f"Failed to enable systemd units because user '{user}' doesn't exist."
|
||||||
) from error
|
) from error
|
||||||
|
for unit in units:
|
||||||
|
self.state.enabled_user_systemd_units.append((user, unit))
|
||||||
|
|
||||||
def disable_user_units(self, units: list[str], user: str):
|
def disable_user_units(self, units: list[str], user: str):
|
||||||
"""
|
"""
|
||||||
Disables the given units for the given user.
|
Disables the given units for the given user.
|
||||||
"""
|
"""
|
||||||
for unit in units:
|
|
||||||
try:
|
|
||||||
self.state.enabled_user_systemd_units.remove((user, unit))
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
try:
|
try:
|
||||||
uid = pwd.getpwnam(user).pw_uid
|
uid = pwd.getpwnam(user).pw_uid
|
||||||
gid = pwd.getpwnam(user).pw_gid
|
gid = pwd.getpwnam(user).pw_gid
|
||||||
@@ -686,3 +681,9 @@ class Systemd:
|
|||||||
raise UserFacingError(
|
raise UserFacingError(
|
||||||
f"Failed to disable systemd units because user '{user}' doesn't exist."
|
f"Failed to disable systemd units because user '{user}' doesn't exist."
|
||||||
) from error
|
) from error
|
||||||
|
|
||||||
|
for unit in units:
|
||||||
|
try:
|
||||||
|
self.state.enabled_user_systemd_units.remove((user, unit))
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user