debian-forge/osbuild/util/path.py
Christian Kellner f05078f66e global: fix PEP-8 formatting
This patch was generated by running `autopep8 --diff` on the
source tree and then applying the diff.
2022-08-05 09:41:05 +02:00

12 lines
413 B
Python

"""Path handling utility functions"""
import os
def in_tree(path: str, tree: str, must_exist: bool = False) -> bool:
"""Return whether the canonical location of 'path' is under 'tree'.
If 'must_exist' is True, the file must also exist for the check to succeed.
"""
path = os.path.abspath(path)
if path.startswith(tree):
return not must_exist or os.path.exists(path)
return False