From 810ab3a2fa89f57fde4d69fda6f59d381a5ed150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Gaillard?= Date: Mon, 19 Jan 2026 17:02:18 +0100 Subject: [PATCH] fix(fs-utils): enhance check_file_exist to support symlink resolution (#766) --- kiauh/utils/fs_utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kiauh/utils/fs_utils.py b/kiauh/utils/fs_utils.py index cd9eb26..8de2a00 100644 --- a/kiauh/utils/fs_utils.py +++ b/kiauh/utils/fs_utils.py @@ -24,13 +24,16 @@ from core.logger import Logger 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 sudo: use sudo if required :return: True, if file exists, otherwise False """ 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: check_output(command, stderr=DEVNULL) return True