mirror of
https://github.com/dw-0/kiauh.git
synced 2026-02-04 16:37:45 +05:00
fix(fs-utils): enhance check_file_exist to support symlink resolution (#766)
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user