Repository navigation
Conversation
symlinkPathsSync checked srcpath with fs.existsSync, which follows symlinks, while the async symlinkPaths uses fs.lstat. So ensureSymlinkSync rejected a srcpath that is itself a broken symlink, which ensureSymlink accepts, and it threw a plain "absolute srcpath does not exist" error without a code where ensureSymlink rejects with ENOENT. Use lstatSync with the same error handling as the async version.
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.
symlinkPathsSynccheckssrcpathwithfs.existsSync, while the asyncsymlinkPathsusesfs.lstat.existsSyncfollows symlinks, so the two disagree whensrcpathis itself a broken symlink:They also differ on a missing
srcpath:ensureSymlinkrejects with anENOENTerror (ENOENT: no such file or directory, ensureSymlink '...'), whileensureSymlinkSyncthrows a plainError('absolute srcpath does not exist')(or'relative ...') with nocode.This PR uses
lstatSyncin both branches ofsymlinkPathsSync, with the same error rewrite as the async version, so the sync API behaves like the async one.User-visible changes to the sync API:
srcpaththat is itself a broken symlink is accepted, as inensureSymlink;srcpaththrows anENOENTerror with acode, instead of the plain "absolute/relative srcpath does not exist" message.Nothing in the repo depends on the old messages.
symlinkPathsSyncis not exported.Tests: added cases to
lib/ensure/__tests__/symlink.test.jsfor a broken-symlinksrcpath, both absolute and relative-to-cwd, and for theENOENTcode on a missingsrcpath. All three fail without the change.npm test(standard,node test.js,node test.mjs): 748 passing.