diff --git a/backend/app/tasks/scan.py b/backend/app/tasks/scan.py index 78f67b4..7f533e2 100644 --- a/backend/app/tasks/scan.py +++ b/backend/app/tasks/scan.py @@ -641,9 +641,18 @@ async def handle_directory_rename(old_dirpath: str, new_dirpath: str) -> dict: ) ) )).scalars().all() + # Path is load-bearing (FKs join on it implicitly via filepath), + # name is purely display. The renamed folder itself gets its + # leaf basename refreshed too so the sidebar tree doesn't show + # stale text. Descendant folders keep their existing name + # because the rename was on the ancestor — only the path changes. + new_basename = os.path.basename(new_prefix) for f in folders: - f.path = new_prefix if f.path == old_prefix else \ - new_prefix + f.path[len(old_prefix):] + if f.path == old_prefix: + f.path = new_prefix + f.name = new_basename + else: + f.path = new_prefix + f.path[len(old_prefix):] source_roots = (await session.execute( select(SourceRoot).where(SourceRoot.path == old_prefix)