Repository navigation
fix(nodeenv): link nodejs.exe without mklink - #415
Merged
Merged
Conversation
mklink ran through cmd with an unquoted command line, so env paths with forward slashes or spaces broke it, and it needs elevation or Developer Mode. Its output was also printed twice and reported at ERROR level, although the environment was fine. Use os.symlink, fall back to a hard link, and only warn if both fail. Fixes #303
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #303.
Problem
On Windows
install_activatecreatedScripts/nodejs.exethrough cmd:That call fails in two ways:
mklinkneeds elevation or Developer Mode, otherwise it reportsYou do not have sufficient privilege to perform this operation.(Better report success whennodejs.execreation fails #303).in_shell=Truecallitruns a bare' '.join(cmd); the quoting loop above it only buildscmd_descfor the debug log. An env path given with forward slashes (nodeenv C:/Temp/.../nenv) makes cmd read/Tempas a switch:Invalid switch - "Temp".(Windows installing npm: shutil.Error / WindowsError [Error 206] The filename or extension is too long #190). A path with a space breaks the same way.The report is also misleading.
callitprints each output line as it reads it and prints the whole buffer again on a nonzero exit, so the singlemklinkline shows up twice, followed byError: Failed to create nodejs.exe linkatERRORlevel. Since #180 the failure is non-fatal andnodeenvexits 0 with a usable env, but the output reads like the run failed.Fix
mklinkis a cmd builtin, which is the only reason a shell was involved. Python does it directly, the way the non-Windows branch already does:os.symlink('node.exe', shim_nodejs)- works with elevation, and without it when Developer Mode is on.os.link(Scripts/node.exe, shim_nodejs)- a hard link needs neither.logger.warningthat says what is lost: nothing, unless something on the system invokes node asnodejs.No shell means no quoting problem and no doubled output, and the common unprivileged case now gets a working
nodejs.exeinstead of an error.Verification
Three tests in
tests/test_install_activate.pyfakeis_WIN, so they run on every platform:test_win_nodejs_symlink_created- a symlink tonode.exein an env path containing a space (skipped on a real Windows host, like the existing symlink test);test_win_nodejs_hardlink_when_symlink_fails-os.symlinkraises, the hard link points at the same file;test_win_nodejs_link_failure_is_a_warning- both raise, one warning and no error.All three fail before the change. The
fake_winfixture used to stubcallitbecause ofmklink; it now stubsos.symlink, soScripts/still holds only the generated scripts.