diff options
author | Maxim Devaev <[email protected]> | 2023-03-05 17:42:29 +0200 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2023-03-05 17:42:29 +0200 |
commit | 880f24dfbcc2590f7eb1ee29150bc9c2691daeb7 (patch) | |
tree | 930be06926b7448739a83426f9a9ebe50981a808 /kvmd | |
parent | 3a7278b0f7bc3ce4369f261b45aa2179bbf63e6f (diff) |
chown only if needed
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/helpers/remount/__init__.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/kvmd/helpers/remount/__init__.py b/kvmd/helpers/remount/__init__.py index f19262c9..14a87769 100644 --- a/kvmd/helpers/remount/__init__.py +++ b/kvmd/helpers/remount/__init__.py @@ -22,6 +22,7 @@ import sys import os +import pwd import shutil import subprocess @@ -74,11 +75,12 @@ def _move(src: str, dest: str) -> None: def _chown(path: str, user: str) -> None: - _log(f"CHOWN --- {user} - {path}") - try: - shutil.chown(path, user) - except Exception as err: - raise SystemExit(f"Can't change ownership: {err}") + if pwd.getpwuid(os.stat(path).st_uid).pw_name != user: + _log(f"CHOWN --- {user} - {path}") + try: + shutil.chown(path, user) + except Exception as err: + raise SystemExit(f"Can't change ownership: {err}") # ===== |