Skip to content

Commit

Permalink
Merge pull request #238 from jhonabreul/bug-path-validity-checks
Browse files Browse the repository at this point in the history
Improve path validity check in path manager
  • Loading branch information
Martin-Molinero authored Nov 28, 2022
2 parents e13502f + 4ee22bd commit 7279ee6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lean/components/util/path_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@ def is_cli_path_valid(self, path: Path) -> bool:
"""
from lean.models.errors import MoreInfoError

relative_path = path

try:
cli_root_dir = self._lean_config_manager.get_cli_root_directory()
relative_path = path.relative_to(cli_root_dir)
except MoreInfoError:
except (MoreInfoError, ValueError):
from platform import system
if system() == "Windows":
# Skip the first component, which contains the drive name
posix_path = path.as_posix()
relative_path = Path(posix_path[posix_path.index('/'):])
first_separator_index = posix_path.find('/')
relative_path = Path(posix_path[first_separator_index:] if first_separator_index != -1 else path)

return relative_path == Path(".") or self.is_path_valid(relative_path)

0 comments on commit 7279ee6

Please sign in to comment.