fix(klipper): handle file access exception for dietpi version file (#658)

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2025-03-09 08:19:32 +01:00
committed by dw-0
parent 41804f0eaa
commit 760f131d1c
2 changed files with 6 additions and 4 deletions

View File

@@ -10,6 +10,7 @@
# ======================================================================= #
from __future__ import annotations
import os
import re
import shutil
from pathlib import Path
@@ -29,15 +30,15 @@ def check_file_exist(file_path: Path, sudo=False) -> bool:
:return: True, if file exists, otherwise False
"""
if sudo:
command = ["sudo", "find", file_path.as_posix()]
try:
command = ["sudo", "find", file_path.as_posix()]
check_output(command, stderr=DEVNULL)
return True
except CalledProcessError:
return False
else:
if file_path.exists():
return True
if os.access(file_path, os.F_OK):
return file_path.exists()
else:
return False