From 42f8d78dd56311ce482e2f0369dd71fae3bfd2f9 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 16 May 2026 23:45:47 +0000 Subject: [PATCH] =?UTF-8?q?fix(downloads):=20drop=20/select=20on=20Windows?= =?UTF-8?q?=20=E2=80=94=20opens=20wrong=20folder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported: clicking "Open Downloads folder" was opening the Documents folder instead of Downloads. Root cause is the classic Windows gotcha: when the path contains a space (e.g. ``C:\Users\Michael Dombaugh\Downloads``), Python's ``subprocess.Popen`` packs the ``/select,...`` argument into a single quoted token, and Explorer's ``/select`` argument parser does NOT accept that form — it silently falls back to whatever the user's default Explorer view is (typically Documents). Resolution paths considered: - ``shell=True`` with a hand-built command string — works but opens the door to shell-injection if a file_name ever contained a quote or special char. - ``cmd /c start "" explorer /select,...`` — same parsing issue. - ctypes ShellExecuteW — pulls in a Windows-only dependency. - **Skip /select. Open the folder directly.** ✓ Going with the last. ``explorer `` reliably opens the folder regardless of spaces in the path; the user finds the freshly-saved file by its name. The previous "highlight the file" nicety wasn't worth the path-parsing fragility — every user folder on Windows is ``C:\Users\`` and every Windows username can contain a space. macOS keeps the ``open -R `` reveal-in-Finder path because macOS argument parsing is sane and that's a strict UX win. 2220 tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/gui/components/_legacy.py | 36 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/gui/components/_legacy.py b/src/gui/components/_legacy.py index 1483137..1cdb2d1 100644 --- a/src/gui/components/_legacy.py +++ b/src/gui/components/_legacy.py @@ -258,14 +258,18 @@ def _open_in_file_manager(folder: "Path", *, select: "Path | None" = None) -> bo """Open the OS file manager at *folder*, optionally highlighting *select*. Windows - ``explorer /select,`` is preferred when *select* is given — - Explorer pops to the foreground with the freshly-saved file - already highlighted. Falls back to ``explorer ``, then - ``os.startfile`` if both fail; ``os.startfile`` is known to - silently no-op or open behind the active window in some Windows - configurations, which is why we don't lead with it. + ``explorer `` only. We deliberately do NOT use + ``explorer /select,``: when the path contains a space + (e.g. ``C:\\Users\\Michael Dombaugh\\Downloads``), Python's + ``subprocess.Popen`` quotes the ``/select,...`` argument as one + unit, and Explorer's ``/select`` parser does not handle that + form — it silently falls back to opening the user's default + view (typically Documents). Opening the bare folder works + reliably regardless of spaces. ``os.startfile`` is kept as a + last-resort fallback only. macOS - ``open -R `` reveals the file in Finder. + ``open -R `` reveals the file in Finder when ``select`` + is given; otherwise just opens the folder. Linux / *BSD ``xdg-open`` on the folder. No reliable cross-distro way to highlight a specific file. @@ -278,19 +282,11 @@ def _open_in_file_manager(folder: "Path", *, select: "Path | None" = None) -> bo import subprocess if sys.platform == "win32": - # explorer.exe with /select wants a literal "/select," followed - # by the path — no space between the comma and the filename, or - # Explorer misinterprets and opens "My Computer" instead. - attempts = [] - if select is not None: - attempts.append(["explorer", f"/select,{select}"]) - attempts.append(["explorer", str(folder)]) - for cmd in attempts: - try: - subprocess.Popen(cmd) - return True - except Exception: - continue + try: + subprocess.Popen(["explorer", str(folder)]) + return True + except Exception: + pass try: os.startfile(str(folder)) # type: ignore[attr-defined] return True