Repository navigation
Pass the R install folder to rig with backslashes on Windows - #19476
Conversation
With forward slashes, rig can't read its existing R links (such as R-release.exe) and stops before installing. Addresses #19468.
There was a problem hiding this comment.
🟡 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_DIRto 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
| if (.rs.platform.isWindows) | ||
| directory <- chartr("/", "\\", directory) |
There was a problem hiding this comment.
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.
ReviewA four-agent review of this branch (code, test coverage, comments, and intent/scope/downstream effects), reading Findings:
Assessment
Actions Taken
|
gtritchie
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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".
| { | ||
| # backslashes on Windows, the same form RInstallJob (SessionRig.cpp) | ||
| # gives 'rig add' (#19468) | ||
| if (.rs.platform.isWindows) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
| # backslashes on Windows, the same form RInstallJob (SessionRig.cpp) | ||
| # gives 'rig add' (#19468) | ||
| if (.rs.platform.isWindows) | ||
| directory <- chartr("/", "\\", directory) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
RStudio E2E - all platformsAll tests passed!
All platforms - commit |
gtritchie
left a comment
There was a problem hiding this comment.
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.

Addresses #19468.
On Windows, RStudio passes the R install folder to rig in
RIG_R_INSTALL_DIRwith forward slashes. Once rig's R links exist in%USERPROFILE%\.local\bin(such asR-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()inSessionRig.R. The converted folder is what the job logs, what it queries rig's directories for, and whatrig addruns with. The helper takes the platform as an argument, so its test intest-rig.Rruns 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.