|
3 | 3 | from .exceptions import FilesInUseError, NoLauncherTemplateError |
4 | 4 | from .fsutils import atomic_unlink, ensure_tree, unlink |
5 | 5 | from .logging import LOGGER |
6 | | -from .pathutils import Path, relative_to |
| 6 | +from .pathutils import Path, PurePath, relative_to |
7 | 7 | from .tagutils import install_matches_any |
8 | 8 |
|
9 | 9 | _EXE = ".exe".casefold() |
@@ -97,6 +97,10 @@ def _create_alias( |
97 | 97 | allow_link=True, |
98 | 98 | _link=os.link): |
99 | 99 | p = cmd.global_dir / name |
| 100 | + # Raise exception if someone has tried to get us to write outside of the |
| 101 | + # intended directory |
| 102 | + if str(p.relative_to(cmd.global_dir)) != PurePath(name).name: |
| 103 | + raise ValueError(f"Invalid alias name: {name}") |
100 | 104 | if not p.match("*.exe"): |
101 | 105 | p = p.with_name(p.name + ".exe") |
102 | 106 | if not isinstance(target, Path): |
@@ -235,6 +239,9 @@ def _parse_entrypoint_line(line): |
235 | 239 | name, sep, rest = line.partition("=") |
236 | 240 | name = name.strip() |
237 | 241 | if name and name[0].isalnum() and sep and rest: |
| 242 | + # "names" that have a parent directory/slash are invalid |
| 243 | + if PurePath(name).parent: |
| 244 | + return None, None, None |
238 | 245 | mod, sep, rest = rest.partition(":") |
239 | 246 | mod = mod.strip() |
240 | 247 | if mod and sep and rest: |
@@ -382,6 +389,14 @@ def create_aliases(cmd, aliases, *, allow_link=True, _create_alias=_create_alias |
382 | 389 | else: |
383 | 390 | LOGGER.debug("Skipping %s alias because " |
384 | 391 | "the launcher template was not found.", alias.name) |
| 392 | + except Exception: |
| 393 | + if install_matches_any(alias.install, getattr(cmd, "tags", None)): |
| 394 | + LOGGER.warn("Skipping %s alias because an unexpected error " |
| 395 | + "occurred.", alias.name) |
| 396 | + LOGGER.debug("TRACEBACK", exc_info=True) |
| 397 | + else: |
| 398 | + LOGGER.debug("Skipping %s alias because an unexpected error " |
| 399 | + "occurred.", alias.name, exc_info=True) |
385 | 400 |
|
386 | 401 |
|
387 | 402 |
|
|
0 commit comments