Repository navigation
Follow Windows .lnk shortcuts in the Files pane and show a shortcut indicator - #18275
Conversation
Plan document for review only -- to be removed before the PR is opened. Addresses #7327.
createFileSystemItem now detects .lnk shell shortcuts, resolves their stored target via IShellLinkW (no shell search, network access, or UI), and emits the target as alias_target plus an is_shortcut flag. Reusing alias_target means the existing alias-aware client logic follows shortcuts unchanged; is_shortcut lets the client label the link badge. Broken shortcuts (deleted targets, non-filesystem targets, garbage content) keep the flag but fall back to plain-file behavior. Addresses #7327.
FileSystemItem gains isShortcut() (backend is_shortcut flag) and includes it in isLink(), so shortcut rows get the link badge with a new "Shortcut" label (en/fr). Shortcut targets travel in alias_target, so navigation, open commands, dialogs, and target-based icons follow shortcuts through the existing alias plumbing; comments at those call sites now say so. Addresses #7327.
Stat'ing a .lnk target on a disconnected share or dead UNC host could block the session main thread for seconds per entry, per listing. resolveWindowsShortcut now also returns the directory-ness stored in the link (WIN32_FIND_DATAW from IShellLinkW::GetPath, no target I/O), and createFileSystemItem trusts that for network targets instead of probing them; local targets keep the cheap exists() check that demotes broken shortcuts to plain-file behavior. Addresses a roborev finding on commit e694d4e. Addresses #7327.
Mirrors files_aliases.test.ts: directory-shortcut navigation, file- shortcut click and open-command opening the target, and columns-mode dedupe of a shortcut plus its target. The fixture creates real .lnk files through PowerShell's WScript.Shell COM interface, driven from the R console so paths resolve against rsession's HOME. Addresses #7327.
- Add a gtest covering non-ASCII shortcut/target names, guarding the UTF-8/UTF-16 round-trip through the shell link APIs - Report COM infrastructure failures (CoCreateInstance/QueryInterface) as not_supported instead of no_such_file_or_directory so logs don't read a broken COM environment as a broken shortcut - Record the failing step and HRESULT when the test fixture cannot create a shortcut, instead of a bare boolean failure - Echo PowerShell output on e2e fixture failure and make the setup sentinel unique per fixture so stale console text can't mask it - Document the MAX_PATH truncation of stored targets (degrades to broken-shortcut behavior) and include <cstdio> explicitly - Fix comments that understated is_shortcut (it gates badge presence via isLink(), not just the label) and overstated getAbsolutePathW() (stored representation, not guaranteed generic form) Addresses #7327.
RStudio E2E - all platformsAll tests passed!
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
kevinushey
left a comment
There was a problem hiding this comment.
Overview
Extends the macOS Finder-alias support (#18191/#18195) to Windows .lnk shortcuts. A new SessionModuleContextWin32.cpp resolves a shortcut's stored target via IShellLinkW/IPersistFile (deliberately without IShellLink::Resolve()), createFileSystemItem() emits the target in the existing alias_target field plus a new is_shortcut flag, and the GWT client reuses all the alias plumbing (resolveAliasTarget()), adding only isShortcut() and a localized badge label.
Correctness -- verified claims
I checked the assertions the design leans on against the codebase; all hold:
- Eager COM init:
SessionMain.cppdoes callCoInitializeEx(COINIT_APARTMENTTHREADED)on the main thread at startup (added for #13078), so the resolver's "no CoInitialize needed" note is accurate, and theCO_E_NOTINITIALIZEDfallback is a clean failure path. core::system::isRemotePathexists on Windows (Win32System.cpp,PathIsNetworkPathW+GetDriveTypeWfallback). The extrarfind("//", 0)guard is justified:FilePathstores generic (forward-slash) form, andPathIsNetworkPathWis backslash-oriented, so the belt-and-suspenders check is real, not redundant.- Structural mirror: the new
#ifdef _WIN32block increateFileSystemItemfaithfully parallels the__APPLE__alias block directly above it (same!isDirgate, same badge-flag-before-resolve ordering, same debug-level logging, sameexists()demotion for broken links) -- with the one intentional divergence (skipexists()for network targets) clearly commented and tested. GetPathsemantics: thehr != S_OK || emptycheck correctly handlesS_FALSE(virtual shortcuts), and theMAX_PATHbuffer is a genuine limit ofIShellLinkW::GetPath(documented in the header as behaving like a broken shortcut), not an arbitrary choice.- e2e structure matches the established
files_aliases.test.tspattern (samebeforeAll/beforeEachshape,test.skipplatform gate, re-home +activateFilesper test).
Design quality
- Routing shortcut targets through
alias_targetis the right call -- navigation, open commands, dialogs, icons, and columns dedupe all work with zero new client logic. Theis_shortcutflag is minimal and only drives the badge/label. - The never-probe-network-targets rule (trust the stored directory-ness) is the most important design decision in the PR and is well-reasoned: a disconnected share can't stall a listing, while a user click on such a shortcut is an acceptable, Explorer-like time to touch the network.
- Error shape (
systemError+hresult/shortcut-pathproperties, distinct errc for COM-infrastructure vs. content failures) mirrorsresolveFinderAliasand is diagnosable. AutoReleaseRAII matches the existing pattern in SessionGit.cpp; the code is exception- and early-return-safe.
Test coverage
Strong. The gtests create real .lnk files through the same COM API Explorer uses, and cover the cases that actually matter: case-insensitive extension, directories named *.lnk, garbage content, deleted targets (including the documented divergence from the macOS ResolveFailsWhenTargetDeleted behavior -- nicely called out), non-ASCII round-trip through the UTF-8/UTF-16 boundary, and the unreachable-UNC contract. Per-step ADD_FAILURE() with HRESULTs in the fixture will make CI breaks readable. The e2e fixture's double failure channel (exit status + script-printed sentinel with a unique name) is careful work.
Minor observations (none blocking)
SetPathon a nonexistent UNC host (FileSystemItemForNetworkShortcutKeepsTarget): some shell versions do light processing inSetPath, so on an unlucky CI host this test could be slow (DNS timeout) rather than wrong. Just something to watch if the Windows gtest job ever gets slow.FilesConstants_fr.propertiesstill ends without a trailing newline after the edit -- trivially worth fixing while touching the file.- Security: parsing
.lnkcontent during a listing uses the same shell code path Explorer runs when it displays a folder, so this adds no exposure beyond what viewing the directory in Explorer already entails. SkippingResolve()also avoids the icon/search side channels. No concerns.
Verdict
High-quality PR -- ship it. The riskiest surface (network stalls during listings) is explicitly designed around and tested, the client reuse keeps the diff small where it counts, and the divergences from the macOS implementation are deliberate and documented rather than accidental. I found no correctness bugs; the only suggestions are the trailing-newline nit and keeping an eye on the UNC gtest's runtime on CI.
…liasing (#18336) * resolve windows shortcut targets to long-form paths; canonicalize e2e sandbox home The scheduled Windows e2e runs have failed on files_shortcuts.test.ts since PR #18275 merged: the sandbox HOME is derived from os.tmpdir(), which on the CI runners contains an 8.3 short-name component (C:\Users\RUNNER~1\...), while the shell stores and reports .lnk targets in long form. createAliasedPath's literal prefix match then fails, so a followed shortcut opens the target as a second, path-distinct document instead of ~/-aliased one. Two fixes: - e2e: canonicalize the sandbox path with fs.realpathSync.native, which (unlike the JS realpath) expands 8.3 short names on Windows. This also fixes the spurious "workdir is not under PW_SANDBOX" teardown warning. - rsession: normalize resolved shortcut targets with GetLongPathName (local paths only, keeping the no-network-I/O contract), so aliasing and duplicate-document detection are robust to short-form or case-mismatched stored targets regardless of environment. * address review: heap retry for long paths, stored-form test guard, sandbox self-guard
On Windows, the Files pane now follows
.lnkshortcuts, fixing a regression we've had since moving to Electron.Clicking a shortcut to a folder navigates to that folder, and clicking (or using an open command on) a shortcut to a file opens the target file. Shortcut rows show the link indicator badge (as symbolic links and macOS Finder aliases do) with a "Shortcut" label and a
name -> targettooltip.This mirrors the macOS Finder alias support from #18191 and #18195, and reuses its client plumbing.
Backend
SessionModuleContextWin32.cppprovidesisWindowsShortcut()(a cheap.lnkextension check that gates the COM work) andresolveWindowsShortcut(), which reads the shortcut's stored target viaIShellLinkW/IPersistFile. It deliberately does not callIShellLink::Resolve(), which can search the disk or hit the network during a listing.createFileSystemItem()emits the resolved target in the existingalias_targetfield — so all alias-aware client logic (navigation, open commands, file dialogs, target-based file icons, columns dedupe) applies unchanged — plus anis_shortcutflag for the badge.exists()check that demotes broken shortcuts to plain-file behavior (badge only)..lnkcontent resolve with an error and likewise fall back to plain-file behavior.Frontend
FileSystemItemgainsisShortcut(), included inisLink();FilesListpicks the "Shortcut" badge label (localized in English and French). Navigation and open behavior come fromalias_targetalone.Tests
WindowsShortcutTestgtest fixture creates real.lnkfiles through the COM API and covers detection (case-insensitive extension, directories named.lnk, nonexistent paths), resolution (file/dir targets, stored directory-ness, non-ASCII names, garbage content, deleted targets), and thecreateFileSystemItemcontract (including broken shortcuts and unreachable UNC targets).FileSystemItemTestscover the new accessors and the resolve contract.files_shortcuts.test.ts) exercises directory navigation, file opening via click and open command, and columns-mode dedupe against a fixture that creates real shortcuts through PowerShell.Verified with a full local build and manual testing on Windows; C++ (378 rsession-scope tests), GWT (545 unit tests), and e2e (4 tests, desktop) suites all pass.
Fixes #18274.