Skip to content

fix: preserve relative symlink targets - #1964

Closed
pol-rivero wants to merge 1 commit into
electron:mainfrom
pol-rivero:main
Closed

pol-rivero wants to merge 1 commit into
electron:mainfrom
pol-rivero:main

Conversation

@pol-rivero

Copy link
Copy Markdown
  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • The changes are appropriately documented (if applicable).
  • The changes have sufficient test coverage (if applicable).
  • The testsuite passes successfully on my local machine (if applicable).

Summarize your changes:

Since v19.0.0 (#1821), copyTemplate() copies the app with fs.promises.cp instead of fs-extra's copy(). Unlike fs-extra, Node's fs.cp resolves relative symlink targets into absolute paths unless verbatimSymlinks: true is passed.
As a result, with derefSymlinks: false, a relative link in the app directory ends up in the packaged app as an absolute symlink, containing the full path of the project directory on the local machine. That link breaks as soon as the packaged app runs on any other machine.

The only workaround is derefSymlinks: true, which replaces every symlink with a full copy of its target, which is suboptimal as it can greatly increase the final size of the bundled app.

This PR passes verbatimSymlinks: !dereference when copying the app, which restores the v18 behavior: symlinks are kept exactly as written.

Please let me know if you want me to make any follow-up changes :)

@pol-rivero
pol-rivero requested a review from a team as a code owner September 26, 2026 13:43
@MarshallOfSound

Copy link
Copy Markdown
Member

I think we should ensure as part of this behavior that:

  • The reletive symlinks target actually exist
  • The relative symlink target does not lead outside of the resulting packaged app

@pol-rivero

Copy link
Copy Markdown
Author

@MarshallOfSound I think that adding this check could cause some problems:

  • It could be quite slow for large apps, especially if they contain many symlinks.
  • It causes an asymmetry between absolute and relative links (absolute links are not checked, it could be confusing for users if we now start checking relative links).
  • There might be legitimate reasons to package broken symlinks into the app (maybe the target is populated later). Adding this check would break those builds, which currently work.

I can add the check anyway, if you want.

NitramO-YT added a commit to NitramO-YT/Github-Desktop that referenced this pull request Oct 7, 2026
Upstream 3.6.7-beta3 moves to @electron/packager 20, whose copy of the
app rewrites every relative link into an absolute path to the build
machine, and works around it with derefSymlinks, which copies each link
in full: the commands of the bundled git, links to a single binary,
double the size of the installed app.

On Linux, derefSymlinks is off again, and the copy keeps the links as
written thanks to a patch of @electron/packager 20.3.0. The patch is the
change proposed upstream in electron/packager#1964 by Pol Rivero, not
yet released, carried as is into the compiled file the package ships.
It goes away once a release includes it. macOS keeps the choice of
upstream.
@NitramO-YT

Copy link
Copy Markdown

Adding a real-world data point, in case it helps weigh this PR.

GitHub Desktop moved to @electron/packager 20.3.0 in desktop/desktop#22928 and set derefSymlinks: true there, to keep macOS signing from rejecting invalid symlink destinations. Between 3.6.7-beta2 and 3.6.7-beta3, the first release with that change, its macOS zips went from about 231 to 471 MB (arm64) and from 249 to 510 MB (x64), while the Windows installers, which have no symlinks, stayed at about 239 MB.

I maintain a Linux build of GitHub Desktop (NitramO-YT/Github-Desktop) and saw the same thing there: the installed app went from 567 to 1139 MB, and the .rpm from 160 to 402 MB. The bundled git accounts for it: it ships most of its commands as relative links to a single binary (git-add -> git), and dereferencing turns each of them into a full copy.

With this PR's change applied to 20.3.0 through patch-package (Electron 44.1.1, derefSymlinks: false on Linux), the links stay as written and the sizes are back to those of the previous release.

Regarding the checks suggested above: in that packaged app, all 148 links are relative, resolve to an existing file and stay inside the app, so they would pass in this case.

@bendemboski

Copy link
Copy Markdown

Note that this is also an issue here -- extraResources used to preserve relative symlinks and now it rewrites them as absolute, which bakes absolute build paths into the packaged application bundle -- not good!

Would it make sense to roll the fix into this PR, or should I open a separate issue/PR/etc?

NitramO-YT added a commit to NitramO-YT/Github-Desktop that referenced this pull request Oct 22, 2026
Upstream 3.6.7 moves to @electron/packager 20, whose copy of the app
rewrites every relative link into an absolute path to the build machine,
and works around it with derefSymlinks, which copies each link in full:
the commands of the bundled git, links to a single binary, double the
size of the installed app.

On Linux, derefSymlinks is off again, and the copy keeps the links as
written thanks to a patch of @electron/packager 20.3.0. The patch is the
change proposed upstream in electron/packager#1964 by Pol Rivero, not
yet released, carried as is into the compiled file the package ships.
It goes away once a release includes it. macOS keeps the choice of
upstream.

The same change has been on linux-beta since 3.6.7-beta3-linux1; the
check of the bundled git in ci-linux.yml requires it here as well.
@sergiou87

Copy link
Copy Markdown

Chiming in from the GitHub Desktop team — we just got a user report about this in desktop/desktop#23236 and would love to see this merged!

As @NitramO-YT noted above, when we upgraded from @electron/packager v18 to v20 in desktop/desktop#22928, we hit macOS codesigning failures with derefSymlinks: false because Node's fs.cp was rewriting relative symlinks in our bundled Git (libexec/git-core) into absolute paths pointing back to the build directory. Switching to derefSymlinks: true unblocked signing, but expanded ~148 symlinks into full binary copies — adding ~495 MiB uncompressed (~44% of the .app bundle) and roughly doubling our macOS release ZIPs.

Since v18 preserved relative symlinks verbatim (via fs-extra), this PR is really just restoring the pre-v19 behavior. And even with the safety checks @MarshallOfSound mentioned in mind, the current v19/v20 behavior is strictly worse: derefSymlinks: false guarantees that relative symlinks end up pointing outside the packaged app (into the build machine's source tree). Would it make sense to land this regression fix as-is and track any additional symlink validation as a follow-up?

Thanks for putting this together, @pol-rivero!

@sergiou87

Copy link
Copy Markdown

@pol-rivero would you mind to rebase this branch on top of the latest main to fix CI checks, please? 🙏

@pol-rivero

Copy link
Copy Markdown
Author

@sergiou87 @MarshallOfSound I've rebased the branch 👍

@MarshallOfSound
MarshallOfSound enabled auto-merge (squash) November 27, 2026 15:48
@hewigovens

Copy link
Copy Markdown

Thanks for the great work @pol-rivero and @sergiou87 , I didn't notice this PR when creating GitHub Desktop issue #23236 👍

@dsanders11

Copy link
Copy Markdown
Member

Superseded by #1985.

@dsanders11 dsanders11 closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants