statement_reconciler: Improve the path matching to handle relative paths and symlinks

This commit is contained in:
Ben Sturmfels 2024-07-19 15:52:19 +10:00
parent 9129a4af6a
commit 1473d24d6e
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0

View file

@ -666,12 +666,13 @@ def parse_repo_relative_path(path: str) -> str:
"""
if not os.path.exists(path):
raise argparse.ArgumentTypeError(f'File {path} does not exist.')
repo = os.getenv('CONSERVANCY_REPOSITORY')
real_path = os.path.realpath(path)
repo = os.path.realpath(os.getenv('CONSERVANCY_REPOSITORY'))
if not repo:
raise argparse.ArgumentTypeError('$CONSERVANCY_REPOSITORY is not set.')
if not path.startswith(repo):
if not real_path.startswith(repo):
raise argparse.ArgumentTypeError(
f'File {path} does not share a common prefix with $CONSERVANCY_REPOSITORY {repo}.'
f'File {real_path} does not share a common prefix with $CONSERVANCY_REPOSITORY {repo}.'
)
return path