From 76c4cc08293505018e4ac85638c3e89cdaaf8d81 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Sat, 16 May 2026 22:25:52 +0000 Subject: [PATCH] Normalize relative media paths. --- mediahive/hivescan/utils.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mediahive/hivescan/utils.py b/mediahive/hivescan/utils.py index c90c90e..a7cf6a2 100644 --- a/mediahive/hivescan/utils.py +++ b/mediahive/hivescan/utils.py @@ -142,19 +142,19 @@ def make_relative_path( path: Optional[str], root: Optional[str] = None ) -> Optional[str]: """ - Convert an absolute path to a path relative to the given root. + Convert an absolute path to a posix-style path relative to the given root. - If root is None, returns the path unchanged. + If root is None, returns the path as a posix string unchanged. """ if path is None: return None + p = Path(path) if root is None: - return path - root_str = str(root).rstrip("/") - if path.startswith(root_str): - rel = path[len(root_str) :] - return rel.lstrip("/") - return path + return p.as_posix() + try: + return p.relative_to(root).as_posix() + except ValueError: + return p.as_posix() def sanitize_filename(name: str) -> str: