mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
chown only if needed
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import pwd
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@@ -74,11 +75,12 @@ def _move(src: str, dest: str) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def _chown(path: str, user: str) -> None:
|
def _chown(path: str, user: str) -> None:
|
||||||
_log(f"CHOWN --- {user} - {path}")
|
if pwd.getpwuid(os.stat(path).st_uid).pw_name != user:
|
||||||
try:
|
_log(f"CHOWN --- {user} - {path}")
|
||||||
shutil.chown(path, user)
|
try:
|
||||||
except Exception as err:
|
shutil.chown(path, user)
|
||||||
raise SystemExit(f"Can't change ownership: {err}")
|
except Exception as err:
|
||||||
|
raise SystemExit(f"Can't change ownership: {err}")
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|||||||
Reference in New Issue
Block a user