Fix crash when creating a patch for a package containing a broken symlink#613
Open
KAMRONBEK wants to merge 1 commit into
Open
Fix crash when creating a patch for a package containing a broken symlink#613KAMRONBEK wants to merge 1 commit into
KAMRONBEK wants to merge 1 commit into
Conversation
Author
|
@ds300 TL;DR: |
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.
Problem
Running
patch-package <pkg>crashes withError: ENOENT: no such file or directory, stat '...'when the package directory contains a symlink whose target does not exist (e.g.react-native'shermes.framework/hermes -> Versions/Current/hermesafter building RN from source).--excludecannot help because the crash happens before ignored files are filtered.Root cause
In
makePatch, the user's package is copied into the tmp repo withcopySync(realpathSync(packagePath), tmpRepoPackagePath)beforeremoveIgnoredFilesruns. On patch-package 6.x (fs-extra 7)copySyncitself crashed stat'ing the dangling symlink, as reported in the issue. On current master (fs-extra 10.1)copySynccopies the dangling link into the tmp tree, and thenremoveIgnoredFilescrashes instead, becauseklaw-synccallsfs.statSyncon every entry, which follows the symlink to its missing target. Either way the ENOENT surfaces before include/exclude filtering can apply.Fix
Pass a
filterto thatcopySynccall which skips entries whose target doesn't exist (existsSyncfollows symlinks, so a dangling symlink returnsfalse). Broken symlinks never enter the tmp tree, which fixes both the old fs-extra copy crash and the current klaw-sync crash. Valid symlinks are unaffected: they are still copied as before, and the existingno-symbolic-linksintegration test (which asserts the friendly "patch-package does not yet support symlinks" error) still passes unchanged. Since patch files cannot represent symlinks anyway (mode 120000 is rejected by the patch parser), skipping broken ones loses nothing.Tests
integration-tests/broken-symlink(modeled onno-symbolic-links/happy-path-yarn): installsleft-pad@1.3.0, creates a dangling symlink insidenode_modules/left-pad, editsindex.js, and runspatch-package left-pad. Snapshots assert the patch is created successfully and contains only theindex.jschanges (no symlink). Without the fix this test fails with the exact ENOENT stat error from the issue (verified by reverting the fix and rebuilding).no-symbolic-linksintegration test and the fullsrc/unit suite pass.Fixes #580