Handle missing components in path canonicalization

The trailing components are not guarantee to exist. Avoid doing a second
stat, just ignore FileNotFoundError exceptions in _canon_subpath.
This commit is contained in:
Yuri D'Elia 2021-10-28 11:51:52 +02:00
parent 037bc078dc
commit 58e1f625ab

View file

@ -159,8 +159,11 @@ def _add_run_options(parser: argparse.ArgumentParser) -> None:
def _canon_subpath(path: str, toplevel: str) -> str:
tail = ''
while len(path):
try:
if os.path.samefile(path, toplevel):
return os.path.join(toplevel, tail)
except FileNotFoundError:
pass
path, base = os.path.split(path)
tail = os.path.join(base, tail)
return tail