debian-forge/osbuild/util/path.py
Simon de Vlieger 3fd864e5a9 osbuild: fix optional-types
Optional types were provided in places but were not always correct. Add
mypy checking and fix those that fail(ed).
2022-07-13 17:31:37 +02:00

11 lines
412 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