Repository navigation
fix the Posit Assistant install on Windows with R < 4.2 and non-ASCII paths - #19628
Conversation
R < 4.2 on Windows read the native-marked UTF-8 paths in the system code page, so a non-ASCII data or temp path made unzip() extract into a different directory than the staging directory rsession checks. Addresses #19625.
unzip() returns normally when R extracts somewhere other than the staging directory, so the empty directory surfaced as a package that declares version '' for protocol ''. Fail instead with an error naming the directory. Addresses #19625.
Addresses #19625.
unzip() reports a zip it cannot open, or an entry it cannot write, as a warning and returns normally, so a partial extraction reached the install checks as if it had succeeded. Extract through .rs.chat.extractPackage, which returns the warnings and errors as the failure reason the way .rs.chat.downloadPackage does, and drop the empty-staging check this makes redundant. Addresses #19625.
Replace verifyExtracted() with a check in verifyDeclaredIdentity(): an extraction into the wrong directory left an empty staging directory, reported as "declares version '' for protocol ''". It now reports "Downloaded package has no package.json in <dir>". Addresses #19625.
RStudio E2E - all platformsAll tests passed!
All platforms - commit |
Code review findingsActionable items from an automated code review of 3e14db6. Important
Suggestions
|
installPackage() removes the staging directory as soon as verifyDeclaredIdentity() fails, so the missing package.json error named a path that no longer existed. It now says which version and protocol were requested, as the mismatch error does. Drop the test that duplicated RejectsAPackageWithoutPackageJson. Addresses #19625.
.rs.chat.failureReason() collects the error and warnings that chat.downloadPackage and chat.extractPackage each gathered by hand. warningsFail keeps their difference: a warning alone fails an extraction, but not a download that returned status 0, such as one using the deprecated wininet method. On the C++ side, callReportingFailure() turns the returned reason into an error for both callers. Addresses #19625.
kevinushey
left a comment
There was a problem hiding this comment.
Looks good to me; nothing blocking. I ran the new chat.downloadPackage / chat.extractPackage tests standalone against the helpers at caf922c on R 4.6.1 and they pass. Treating any unzip() warning as a failure also looks safe: everything it warns about (corrupt archive, CRC or write error, ../ path components, extraction through a symlink) is a bad extraction.
Two notes, neither needing action before merge:
- No automated test covers the three
addUtf8Paramcall sites; reverting them leaves every test passing. Reproducing the bug needs a non-UTF-8 Windows session (R <= 4.1), so the manual run in the description is the coverage here. - The description's Testing section still lists "a new test for an empty staging directory", which a later commit dropped. Worth trimming before the squash.
| // on Windows, native is the system code page, so a non-ASCII path (a user | ||
| // name such as José) would name a different directory in R than here. | ||
| r::exec::RFunction extract(".rs.chat.extractPackage"); | ||
| extract.addUtf8Param("zipfile", packagePath); |
There was a problem hiding this comment.
Non-blocking, and I don't think it needs a change. On POSIX this trades one edge case for another: a FilePath there holds whatever bytes the filesystem uses, and R honours the UTF-8 mark by translating to the session's native encoding. In a non-UTF-8 locale with a non-ASCII data or temp directory, the native-marked path used to work and the UTF-8-marked one doesn't (R 4.6.1 on macOS, unzip() into a directory under café/):
LC_ALL=C unable to translate '.../caf<U+00E9>/out' to native encoding
LC_ALL=en_US.ISO8859-1 'exdir' does not exist
The session already forces a UTF-8 charset on Linux and warns when it can't, utf8ToSystem() assumes the same, and the other addUtf8Param(path) call sites behave this way, so this is consistent with the rest of the codebase. Mentioning it because the comment reads as if these paths are UTF-8 on every platform.
Fixes #19625.
On Windows with R < 4.2, installing Posit Assistant failed when the user data or temp path had non-ASCII characters.
RFunction::addParam()marks strings as native encoding, which there is the system code page, so R read a UTF-8éaséandunzip()extracted into a sibling directory. The install then reportedDownloaded package declares version '' for protocol ''and left the extracted package behind.destfile,zipfile,exdir) are passed to R withaddUtf8Param()..rs.chat.extractPackagehelper.unzip()reports a zip it can't open, or an entry it can't write, as a warning and returns normally, so any warning or error fails the extraction and becomes the reason shown..rs.chat.downloadPackageand the new helper share their condition handling in.rs.chat.failureReason(). For a download, a warning only fails it alongside an error or a non-zero status, as before.verifyDeclaredIdentity()reports a missingpackage.json, with the requested version and protocol, instead of a blank declared version.Characters outside the system code page (e.g. Chinese on an English-language system) still can't be used with R < 4.2. The install now fails with R's reason. The NEWS entry says so.
The same
addParam(getAbsolutePath())pattern in the Files pane upload is filed separately as #19627.Testing
RSTUDIO_DATA_HOMEandTEMPboth pointing to directories ending in-é: Posit Assistant installed and selected slot 1.12.0. Noédirectory was created and no staging directory was left behind. With the released build and onlyRSTUDIO_DATA_HOMEset, the install failed as described in Posit Assistant install fails on Windows with R < 4.2 when the user data path has non-ASCII characters #19625.unzip()behavior itself, outside RStudio: native-marked paths fail, UTF-8-marked paths extract correctly. R 4.6.1 handles both.rsessiontests:ChatInstallation*pass, including a new test for an empty staging directory.test-chat.Rpasses on R 4.6.1, including newchat.extractPackagetests that run the realunzip()on a valid zip and a corrupt zip. The new tests also pass when run standalone on R 4.1.3.RSTUDIO_DATA_HOMEandTEMPwere used to simulate it.