Skip to content

Follow Windows .lnk shortcuts in the Files pane and show a shortcut indicator - #18275

Merged
gtritchie merged 11 commits into
mainfrom
feature/windows-lnk-shortcuts
Jul 17, 2026
Merged

gtritchie merged 11 commits into
mainfrom
feature/windows-lnk-shortcuts

Conversation

@gtritchie

@gtritchie gtritchie commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

On Windows, the Files pane now follows .lnk shortcuts, 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 -> target tooltip.

This mirrors the macOS Finder alias support from #18191 and #18195, and reuses its client plumbing.

Backend

  • New SessionModuleContextWin32.cpp provides isWindowsShortcut() (a cheap .lnk extension check that gates the COM work) and resolveWindowsShortcut(), which reads the shortcut's stored target via IShellLinkW/IPersistFile. It deliberately does not call IShellLink::Resolve(), which can search the disk or hit the network during a listing.
  • createFileSystemItem() emits the resolved target in the existing alias_target field — so all alias-aware client logic (navigation, open commands, file dialogs, target-based file icons, columns dedupe) applies unchanged — plus an is_shortcut flag for the badge.
  • Network targets (UNC paths, mapped network drives) are never probed during a listing; directory-ness comes from the metadata stored in the link, so a disconnected share cannot stall the session. Local targets keep a cheap exists() check that demotes broken shortcuts to plain-file behavior (badge only).
  • Shortcuts without a file-system target (e.g. Control Panel applets) and unreadable .lnk content resolve with an error and likewise fall back to plain-file behavior.

Frontend

  • FileSystemItem gains isShortcut(), included in isLink(); FilesList picks the "Shortcut" badge label (localized in English and French). Navigation and open behavior come from alias_target alone.

Tests

  • WindowsShortcutTest gtest fixture creates real .lnk files 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 the createFileSystemItem contract (including broken shortcuts and unreachable UNC targets).
  • GWT FileSystemItemTests cover the new accessors and the resolve contract.
  • A Windows-only Playwright spec (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.

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.
The feature previously cited #7327, a closed-stale report of the same
problem; #18274 is the canonical issue the upcoming PR will fix.

Addresses #18274.
@gtritchie gtritchie added this to the 2026.08 (Yellow Yarrow) milestone Jul 16, 2026
@gtritchie
gtritchie requested a review from kevinushey July 16, 2026 23:15
@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
1826 0 76 2
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ desktop-linux 460 0 14 1
✅ desktop-macos 456 0 19 0
✅ desktop-windows 464 0 16 1
✅ server-linux 446 0 27 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit 3dc3dd19cbeed44cfca464a8536391433337bdc8 - Run #233

@posit-snyk-bot

posit-snyk-bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@kevinushey kevinushey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.cpp does call CoInitializeEx(COINIT_APARTMENTTHREADED) on the main thread at startup (added for #13078), so the resolver's "no CoInitialize needed" note is accurate, and the CO_E_NOTINITIALIZED fallback is a clean failure path.
  • core::system::isRemotePath exists on Windows (Win32System.cpp, PathIsNetworkPathW + GetDriveTypeW fallback). The extra rfind("//", 0) guard is justified: FilePath stores generic (forward-slash) form, and PathIsNetworkPathW is backslash-oriented, so the belt-and-suspenders check is real, not redundant.
  • Structural mirror: the new #ifdef _WIN32 block in createFileSystemItem faithfully parallels the __APPLE__ alias block directly above it (same !isDir gate, same badge-flag-before-resolve ordering, same debug-level logging, same exists() demotion for broken links) -- with the one intentional divergence (skip exists() for network targets) clearly commented and tested.
  • GetPath semantics: the hr != S_OK || empty check correctly handles S_FALSE (virtual shortcuts), and the MAX_PATH buffer is a genuine limit of IShellLinkW::GetPath (documented in the header as behaving like a broken shortcut), not an arbitrary choice.
  • e2e structure matches the established files_aliases.test.ts pattern (same beforeAll/beforeEach shape, test.skip platform gate, re-home + activateFiles per test).

Design quality

  • Routing shortcut targets through alias_target is the right call -- navigation, open commands, dialogs, icons, and columns dedupe all work with zero new client logic. The is_shortcut flag 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-path properties, distinct errc for COM-infrastructure vs. content failures) mirrors resolveFinderAlias and is diagnosable.
  • AutoRelease RAII 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)

  • SetPath on a nonexistent UNC host (FileSystemItemForNetworkShortcutKeepsTarget): some shell versions do light processing in SetPath, 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.properties still ends without a trailing newline after the edit -- trivially worth fixing while touching the file.
  • Security: parsing .lnk content 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. Skipping Resolve() 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.

@gtritchie
gtritchie merged commit 6d9a0ab into main Jul 17, 2026
24 checks passed
@gtritchie
gtritchie deleted the feature/windows-lnk-shortcuts branch July 17, 2026 16:59
kevinushey added a commit that referenced this pull request Jul 23, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Files pane: follow Windows .lnk shortcuts and show a link indicator

3 participants