From ad079dc8c51bff237df25ce887fdba6b3ee67a8f Mon Sep 17 00:00:00 2001 From: David Waterman Date: Fri, 22 Nov 2024 15:55:15 +0000 Subject: [PATCH] Resolve path only if accessible, otherwise return unchanged Fixes #771 --- src/dxtbx/serialize/filename.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/dxtbx/serialize/filename.py b/src/dxtbx/serialize/filename.py index 8427de4b6..1f60f7720 100644 --- a/src/dxtbx/serialize/filename.py +++ b/src/dxtbx/serialize/filename.py @@ -14,11 +14,15 @@ def resolve_path(path, directory=None): directory (Optional[str]): The local path to resolve relative links Returns: - str: The absolute path to the file to read + str: The absolute path to the file to read if accessible, otherwise + return the original path as provided """ if not path: return "" - path = os.path.expanduser(os.path.expandvars(path)) - if directory and not os.path.isabs(path): - path = os.path.join(directory, path) - return os.path.abspath(path) + trial_path = os.path.expanduser(os.path.expandvars(path)) + if directory and not os.path.isabs(trial_path): + trial_path = os.path.join(directory, trial_path) + if os.path.exists(trial_path): + return os.path.abspath(trial_path) + else: + return path