fix(fs-utils): enhance check_file_exist to support symlink resolution (#766)

This commit is contained in:
Théo Gaillard
2026-01-19 17:02:18 +01:00
committed by GitHub
parent 6c9a78496a
commit 810ab3a2fa

View File

@@ -24,13 +24,16 @@ from core.logger import Logger
def check_file_exist(file_path: Path, sudo=False) -> bool: def check_file_exist(file_path: Path, sudo=False) -> bool:
""" """
Helper function for checking the existence of a file | Helper function for checking the existence of a file.
Also works with symlinks (returns False if broken) |
:param file_path: the absolute path of the file to check :param file_path: the absolute path of the file to check
:param sudo: use sudo if required :param sudo: use sudo if required
:return: True, if file exists, otherwise False :return: True, if file exists, otherwise False
""" """
if sudo: if sudo:
command = ["sudo", "find", file_path.as_posix()] # -L forces find to follow symlinks
# -maxdepth = 0 avoids losing time if `file_path` is a directory
command = ["sudo", "find", "-L", file_path.as_posix(), "-maxdepth", "0"]
try: try:
check_output(command, stderr=DEVNULL) check_output(command, stderr=DEVNULL)
return True return True