Skip to content

Pass the R install folder to rig with backslashes on Windows - #19476

Merged
kevinushey merged 3 commits into
mainfrom
bugfix/19468-rig-install-dir-backslashes
Nov 10, 2026
Merged

kevinushey merged 3 commits into
mainfrom
bugfix/19468-rig-install-dir-backslashes

Conversation

@ronblum

@ronblum ronblum commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Addresses #19468.

On Windows, RStudio passes the R install folder to rig in RIG_R_INSTALL_DIR with forward slashes. Once rig's R links exist in %USERPROFILE%\.local\bin (such as R-release.exe), rig 0.11.0 can't match them against that folder and stops with "Cannot extract R version from C:\Users<user>.local\bin\R-release.exe, invalid R link file?", so "Install and Switch to R" installs nothing.

The install job now converts the folder to backslashes on Windows before it reaches rig, through a new helper, .rs.rig.installDirForRig() in SessionRig.R. The converted folder is what the job logs, what it queries rig's directories for, and what rig add runs with. The helper takes the platform as an argument, so its test in test-rig.R runs on every OS. Other platforms are unchanged.

Not covered here: a destination other than the folder rig's existing links point into still fails, because rig 0.11.0 fails on any link outside the current root. That is fixed upstream by r-lib/rig#507, which isn't released yet; #19561 tracks updating the bundled rig.

With forward slashes, rig can't read its existing R links (such as
R-release.exe) and stops before installing.

Addresses #19468.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The Windows-only path conversion lacks regression coverage because the existing test skips Windows; a Windows-capable test should verify backslash conversion and restoration of the previous RIG_R_INSTALL_DIR value.

1 open issue
What changed in this PR

This PR addresses #19468 by passing Windows-style paths to rig, preventing existing R links from blocking “Install and Switch to R.”

Changes:

  • Converts RIG_R_INSTALL_DIR to backslashes on Windows in both the install job and the directory-query helper.
  • Leaves path handling unchanged on other platforms.
File Description
src/​cpp/​session/​modules/​SessionRig.R Converts the destination to backslashes before querying rig’s user directories on Windows.
src/​cpp/​session/​modules/​SessionRig.cpp Converts the install directory to backslashes before passing it to rig on Windows.

Review effort: Balanced

Comment thread src/cpp/session/modules/SessionRig.R Outdated
Comment on lines +677 to +678
if (.rs.platform.isWindows)
directory <- chartr("/", "\\", directory)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Leaving this out: Windows CI runs only the C++ test scopes (rstudio-tests.bat --scope core,rsession in jenkins/Jenkinsfile.windows), so a Windows-only testthat test would never run in CI. See Assessment item 4 in the review comment.

@ronblum

ronblum commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Review

A four-agent review of this branch (code, test coverage, comments, and intent/scope/downstream effects), reading SessionRig.cpp, SessionRig.R and test-rig.R in full. No critical or important problems in the change. Checked against rig 0.11.0's source: rig accepts an alias link (such as R-release.exe) only when its target starts with RIG_R_INSTALL_DIR as given plus a backslash, so a folder with forward slashes never matches. Drive roots (D:/) and UNC paths (//server/share) also convert correctly.

Findings:

  1. The job log still printed the folder with forward slashes, while rig got backslashes.
  2. The C++ comment could name the rig version and the exact error, and the new block separated the existing comment from the setenv it describes.
  3. The R comment pointed to RInstallJob without naming its file, and didn't say why the conversion is there.
  4. No test covers the Windows conversion. A Windows-only testthat test with a .cmd stand-in for rig could cover the R half; the C++ half isn't reachable from testthat.
  5. FilePath::getAbsolutePathNative() was suggested in place of std::replace.
  6. Possible remaining gap, not reproduced: if the chosen install folder isn't rig's default and rig's alias links point into the default folder, rig's prefix check would still fail.

Assessment

  1. Take: the log should show what rig receives.
  2. Take.
  3. Take.
  4. Skip: Windows CI runs only the C++ scopes (rstudio-tests.bat --scope core,rsession in jenkins/Jenkinsfile.windows), so the test would never run in CI.
  5. Skip: on Windows it returns the path as stored, and FilePath doesn't convert separators, so the forward slashes would remain.
  6. Out of scope for this change; worth reproducing separately.

Actions Taken

  1. b343db8 moves the conversion above the log line, so the job log shows the folder rig gets.
  2. The same commit rewrites both comments to name rig 0.11.0, the error, and the issue.

@ronblum ronblum self-assigned this Nov 6, 2026
@ronblum
ronblum requested a review from kevinushey November 6, 2026 19:41

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This fixes the default-folder case. Nothing here is a regression. The main open question is whether the custom-folder case (first comment) is handled in this PR or tracked as a follow-up. If it's a follow-up, the "changes requested" state is procedural.

core::system::Options environment;
core::system::environment(&environment);
core::system::setenv(&environment, "RIG_R_INSTALL_DIR", directory_);
core::system::setenv(&environment, "RIG_R_INSTALL_DIR", rigDirectory);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This fixes the case where the destination is the folder rig's existing alias links point into, but not a destination the user changes in the dialog.

In rig 0.11.0, rig add <ver> --user checks for an existing install before downloading. That check goes through find_installed_matching → sc_get_list_details → find_aliases (mod.rs#L389). For each R-release/R-oldrel/R-next link, find_r_version_in_link (mod.rs#L1348-L1371) requires the link's target to start with RIG_R_INSTALL_DIR + \, ignoring case. Take a user whose R-release.exe points at %APPDATA%\rig\data\r\4.5.1\bin\R.exe and who changes the destination to D:\R. They still get "Cannot extract R version from …R-release.exe, invalid R link file?"

A rarer variant: the default folder reached through a junction or symlink. validateInstallDir's normalizePath() resolves those on Windows, so the path rig gets differs from the one it wrote into the link, even with backslashes.

Can this be handled here? If not, could it get a follow-up issue, so "Addresses #19468" stays accurate?

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.

Not in this PR: the failure is inside rig 0.11.0 itself (find_aliases fails the whole rig add on a link outside the root), and there is no clean way around it from RStudio short of touching the user's links. It's fixed upstream by r-lib/rig#507 (for r-lib/rig#506), which skips such links, and that covers the junction/symlink variant too. That fix isn't in a release yet (v0.11.1 predates it), so I filed #19561 to update the bundled rig once it is. This PR keeps to the default-folder case, and stays "Addresses #19468".

Comment thread src/cpp/session/modules/SessionRig.R Outdated
{
# backslashes on Windows, the same form RInstallJob (SessionRig.cpp)
# gives 'rig add' (#19468)
if (.rs.platform.isWindows)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Both new branches run only on Windows, and every test that reaches userDirs/userInstallBegin skips on Windows (test-rig.R lines 133, 855, 936, 976, 1145). Nothing exercises the conversion. Moving it into a small helper that takes the platform as an argument would let it be tested on every OS.

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.

Done in fa87e4a: the conversion is now .rs.rig.installDirForRig(directory, windows = .rs.platform.isWindows), and a new test in test-rig.R exercises both platform values on every OS (drive root, UNC path, already-backslashed input, and that nothing changes off Windows).

Comment thread src/cpp/session/modules/SessionRig.R Outdated
# backslashes on Windows, the same form RInstallJob (SessionRig.cpp)
# gives 'rig add' (#19468)
if (.rs.platform.isWindows)
directory <- chartr("/", "\\", directory)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional: I don't think this changes anything on Windows. There, the only values used from userDirs() come from binary_dir. rig sets binary_dir to %USERPROFILE%\.local\bin whatever RIG_R_INSTALL_DIR is (utils.rs#L410-L425), and rig system dirs doesn't read the alias links. Either drop this block, or pass the already-converted rigDirectory to .rs.rig.userInstallBegin (SessionRig.cpp:225) so the conversion lives in one place.

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.

Agreed, dropped in fa87e4a. The install job now converts once through the helper and passes that folder to .rs.rig.userInstallBegin as well as to rig, so the conversion lives in one place.

@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.

Checked the conversion against rig 0.11.0: get_r_install_dir() on Windows only trims a trailing backslash from RIG_R_INSTALL_DIR, and find_r_version_in_link compares the link target against that value plus \, so a forward-slash root can never match and the backslash form is the right thing to hand rig. The default-folder case from #19468 is fixed by this.

Nothing to add to Gary's open points (custom destination, the untested Windows-only branches, and whether the userDirs block matters). One note on the custom-destination case: that failure is in rig itself. find_aliases bails out of the whole rig add when any R-release/R-oldrel/R-next link points outside the configured root, where skipping that alias would do. Any destination other than the folder the existing links point into will hit it, so the complete fix is upstream in r-lib/rig; it'd be worth filing there and linking it from the follow-up issue, if this PR keeps to the default-folder case.

No NEWS entry is needed since the install flow hasn't shipped yet.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

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

Passed Failed Skipped Flaky
5455 0 242 4
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 4 0 16 0
✅ desktop-linux 1366 0 45 1
✅ desktop-macos 1372 0 40 1
✅ desktop-windows 1360 0 56 2
✅ server-linux 1305 0 53 0
✅ setup 48 0 32 0

View report online


All platforms - commit fa87e4a835a00cf234f68131b01a9a184b2b2ae6 - Run #2167

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Both points are addressed in fa87e4a, and the custom-folder case is tracked in #19561. Since r-lib/rig#507 also converts forward slashes itself, .rs.rig.installDirForRig() can likely go once #19561 updates the bundled rig.

@kevinushey
kevinushey merged commit 967902a into main Nov 10, 2026
41 checks passed
@kevinushey
kevinushey deleted the bugfix/19468-rig-install-dir-backslashes branch November 10, 2026 21:56
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.

4 participants