f
This commit is contained in:
@@ -369,7 +369,11 @@ def is_elevated() -> bool:
|
||||
return False
|
||||
else:
|
||||
try:
|
||||
return os.geteuid() == 0
|
||||
# Use getattr for platform-specific os methods to satisfy Mypy
|
||||
geteuid = getattr(os, "geteuid", None)
|
||||
if geteuid:
|
||||
return bool(geteuid() == 0)
|
||||
return False
|
||||
except Exception:
|
||||
return False
|
||||
except Exception:
|
||||
@@ -476,9 +480,9 @@ def fix_permissions_unix(
|
||||
user = getpass.getuser()
|
||||
|
||||
try:
|
||||
pw = pwd.getpwnam(user)
|
||||
pw = pwd.getpwnam(user) # type: ignore[attr-defined]
|
||||
uid = pw.pw_uid
|
||||
gid = pw.pw_gid if not group else grp.getgrnam(group).gr_gid
|
||||
gid = pw.pw_gid if not group else grp.getgrnam(group).gr_gid # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
logging.warning("Could not resolve user/group to uid/gid; skipping chown.")
|
||||
return False
|
||||
@@ -500,16 +504,18 @@ def fix_permissions_unix(
|
||||
except Exception:
|
||||
# Best-effort fallback: chown/chmod individual entries
|
||||
for root_dir, dirs, files in os.walk(path):
|
||||
try:
|
||||
os.chown(root_dir, uid, gid)
|
||||
except Exception:
|
||||
pass
|
||||
for fn in files:
|
||||
fpath = os.path.join(root_dir, fn)
|
||||
if hasattr(os, "chown"):
|
||||
try:
|
||||
os.chown(fpath, uid, gid)
|
||||
os.chown(root_dir, uid, gid)
|
||||
except Exception:
|
||||
pass
|
||||
for fn in files:
|
||||
fpath = os.path.join(root_dir, fn)
|
||||
if hasattr(os, "chown"):
|
||||
try:
|
||||
os.chown(fpath, uid, gid)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Fix modes: directories 0o755, files 0o644 (best-effort)
|
||||
for root_dir, dirs, files in os.walk(path):
|
||||
@@ -1454,11 +1460,12 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
if p.exists():
|
||||
client_found = p
|
||||
break
|
||||
|
||||
run_client_script = None
|
||||
if client_found:
|
||||
# Prefer run_client helper located in the cloned repo; if missing, fall back to top-level scripts folder helper.
|
||||
script_dir = Path(__file__).resolve().parent
|
||||
helper_candidates = [dest / "run_client.py", script_dir / "run_client.py"]
|
||||
run_client_script = None
|
||||
for cand in helper_candidates:
|
||||
if cand.exists():
|
||||
run_client_script = cand
|
||||
@@ -1477,7 +1484,7 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
)
|
||||
else:
|
||||
if getattr(args, "install_service", False):
|
||||
if run_client_script.exists():
|
||||
if run_client_script and run_client_script.exists():
|
||||
cmd = [
|
||||
str(venv_py),
|
||||
str(run_client_script),
|
||||
@@ -1513,7 +1520,7 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
dest / "run_client.py",
|
||||
)
|
||||
if getattr(args, "uninstall_service", False):
|
||||
if run_client_script.exists():
|
||||
if run_client_script and run_client_script.exists():
|
||||
cmd = [
|
||||
str(venv_py),
|
||||
str(run_client_script),
|
||||
|
||||
Reference in New Issue
Block a user