asar icon indicating copy to clipboard operation
asar copied to clipboard

--unpack-dir does not unpack symlinks

Open romaincointepas opened this issue 9 years ago • 4 comments
trafficstars

asar.unpackDir does not unpack symlinks into app.asar.unpacked/mydir (files and subdirectories are unpacked there, symlinks are not).

Tested with relative symlinks that points to files inside the directory that is being unpacked on OS X.

romaincointepas avatar Jul 20 '16 17:07 romaincointepas

After some testing, it seems that at https://github.com/electron/asar/blob/master/src/asar.coffee#L107:

  • shouldUnpack is never defined and used to check if the symlink should be unpacked.
  • nothing is being added to the files array if shouldUnpack ends up being true (not sure if links should be added to files if shouldUnpack is false though as they seem to be treated differently inside an asar archive).
  • copyFileToSync is then never called for links that should be unpacked

I would be happy to do a PR but I'm not sure I'm seeing the full picture (and all the potential edge cases when dealing with links). Here is how I would do it:

  • Treat links as files if shouldUnpack is true (meaning add them to the files array, with maybe an additional property isLink: true).
  • They will then go through copyFileToSync() and in there, check for .isSymbolicLink() and if true, copy the link using fs.symlinkSync.

@kevinsawicki Thoughts?

romaincointepas avatar Nov 05 '16 17:11 romaincointepas

Just stumbled upon this issue as part of trying to package git into an ASAR archive while also dealing with the fact that Git is an executable.

A bit of context:

  • To reduce the overall size on disk, Git uses symlinks in many places - for example git-remote-https is just a symlink to git-remote-http. This can be disabled when compiling Git, but it results in duplicated binaries everywhere - and will result in a larger .asar.unpacked folder when packaging the Electron app.

  • Symlinks are added to the .asar file, but if your symlink is covered by the --unpack-dir argument, it won't be copied over to the .asar.unpacked folder when creating the archive.

  • Git explicitly looks for the symlink at runtime, and because it's been stripped out of the .asar.unpacked archive it'll fail in several hilarious ways.

Not sure if there's other context on this decision I'm missing or something that will break if we support this, but if there's a :thumbsup: from someone on the core team about continuing down this path I'm happy to bash together a patch using what I've found and what @romaincointepas has found above.

shiftkey avatar Jun 21 '17 12:06 shiftkey

FYI @paulcbetts @smashwilson @binarymuse @kuychaco - why we won't currently be able to put Git into an ASAR

shiftkey avatar Jun 21 '17 12:06 shiftkey

Is there any progress on this issue? I need to be able to unpack a framework on Mac and it doesn't work. As Mac framework is a directory with multiple symlinks, skipping symlinks make framework structure invalid

vyunikov avatar Jun 28 '20 17:06 vyunikov