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