summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2023-03-05 17:42:29 +0200
committerMaxim Devaev <[email protected]>2023-03-05 17:42:29 +0200
commit880f24dfbcc2590f7eb1ee29150bc9c2691daeb7 (patch)
tree930be06926b7448739a83426f9a9ebe50981a808
parent3a7278b0f7bc3ce4369f261b45aa2179bbf63e6f (diff)
chown only if needed
-rw-r--r--kvmd/helpers/remount/__init__.py12
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}")
# =====