minor clean up

This commit is contained in:
ducklet 2023-02-11 18:30:31 +01:00
parent d399d7caba
commit 54cdfa4685
2 changed files with 10 additions and 3 deletions

View file

@ -342,6 +342,7 @@ def _add_parents(conn: Connection, *, location: str, hostname: str) -> "int | No
d = _fake_entry(p, hostname=hostname, now=datetime.now(), parent_id=p_id) d = _fake_entry(p, hostname=hostname, now=datetime.now(), parent_id=p_id)
d = get_or_add(conn, d) d = get_or_add(conn, d)
if isinstance(d, dict): if isinstance(d, dict):
log.warning("Added forged parent: %a:%a", hostname, str(p))
p_id = d["id"] p_id = d["id"]
else: else:
p_id = d.id p_id = d.id

View file

@ -245,14 +245,15 @@ def _parse_pathspec(pathspec: str) -> "tuple[str | None, str]":
def _clean_dirname(loc: str, *, force_absolute: bool = True) -> str: def _clean_dirname(loc: str, *, force_absolute: bool = True) -> str:
"""Ensure the given location ends with a single `/`.
If `force_absolute` is `True`, also ensure the location starts with `/`.
"""
if force_absolute and not loc.startswith("/"): if force_absolute and not loc.startswith("/"):
loc = "/" + loc loc = "/" + loc
if not loc.endswith("/"): if not loc.endswith("/"):
loc += "/" loc += "/"
return loc return loc
# if loc != "/" and loc.endswith("/"):
# return loc[:-1]
# return loc
_Hostname = str _Hostname = str
@ -456,6 +457,11 @@ def _ingest_ls_add_only(
def _dict_from_lsfile(f: ls_parser.File) -> "dict[str, Any]": def _dict_from_lsfile(f: ls_parser.File) -> "dict[str, Any]":
"""Create a dict compatible with `models.File`.
This avoids creating a dataclass instance and calling `asdict` on it, which
is a relatively expensive operation.
"""
mode = f.mode[0] mode = f.mode[0]
if mode == "-": if mode == "-":
mode = "f" mode = "f"