diff options
author | Maxim Devaev <[email protected]> | 2024-08-20 05:43:47 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2024-08-20 05:43:47 +0300 |
commit | 39422f37ac421c94a010400f741fb8ad4c73c64f (patch) | |
tree | fd68ad1dec909db5dd06ae19c80b1e18a984e49a /kvmd/helpers | |
parent | 06b69d3dde2ffe8d3236aff18c6bc4f00ae005de (diff) |
sticky pst
Diffstat (limited to 'kvmd/helpers')
-rw-r--r-- | kvmd/helpers/remount/__init__.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/kvmd/helpers/remount/__init__.py b/kvmd/helpers/remount/__init__.py index e41bbbfd..716b9c72 100644 --- a/kvmd/helpers/remount/__init__.py +++ b/kvmd/helpers/remount/__init__.py @@ -23,6 +23,7 @@ import sys import os import pwd +import grp import shutil import subprocess @@ -87,11 +88,28 @@ def _chown(path: str, user: str) -> None: if pwd.getpwuid(os.stat(path).st_uid).pw_name != user: _log(f"CHOWN --- {user} - {path}") try: - shutil.chown(path, user) + shutil.chown(path, user=user) except Exception as err: raise SystemExit(f"Can't change ownership: {err}") +def _chgrp(path: str, group: str) -> None: + if grp.getgrgid(os.stat(path).st_gid).gr_name != group: + _log(f"CHGRP --- {group} - {path}") + try: + shutil.chown(path, group=group) + except Exception as err: + raise SystemExit(f"Can't change group: {err}") + + +def _chmod(path: str, mode: int) -> None: + _log(f"CHMOD --- 0o{mode:o} - {path}") + try: + os.chmod(path, mode) + except Exception as err: + raise SystemExit(f"Can't change permissions: {err}") + + # ===== def _fix_msd(part: Partition) -> None: # First images migration @@ -112,13 +130,21 @@ def _fix_msd(part: Partition) -> None: if part.user: _chown(part.root_path, part.user) + if part.group: + _chgrp(part.root_path, part.group) def _fix_pst(part: Partition) -> None: path = os.path.join(part.root_path, "data") _mkdir(path) if part.user: + _chown(part.root_path, part.user) _chown(path, part.user) + if part.group: + _chown(part.root_path, part.group) + _chgrp(path, part.group) + if part.user and part.group: + _chmod(part.root_path, 0o1775) # ===== |