From 880f24dfbcc2590f7eb1ee29150bc9c2691daeb7 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Sun, 5 Mar 2023 17:42:29 +0200 Subject: chown only if needed --- kvmd/helpers/remount/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'kvmd') 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}") # ===== -- cgit v1.2.3