From f4618ddf97cb574b9d22b4a689d96cc714d1cef9 Mon Sep 17 00:00:00 2001 From: Claudio Date: Mon, 11 May 2026 13:46:06 +0200 Subject: [PATCH] fix(rename): refresh Folder.name on webhook-driven directory rename handle_directory_rename updated Folder.path but left Folder.name as the old leaf basename. Path is load-bearing; name is purely display, but a stale name shows wrong text in the sidebar tree until the next manual refresh. Now sets folder.name = basename(new_prefix) on the renamed folder itself; descendants keep their existing names because the rename was on an ancestor (only their paths shift). Same correctness as the existing PATCH /folders/{id} endpoint, which also updates both name and path. --- backend/app/tasks/scan.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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)