FredrikNoren / ungit

The easiest way to use git. On any platform. Anywhere.
MIT License
10.44k stars 639 forks source link

Electron version struggles with app.asar #1523

Open victorbnl opened 2 years ago

victorbnl commented 2 years ago

I'm running the electron version and ungit crashes if there is an app.asar (seems to depend on which app.asar it is, and where the file is located) in the folder

2022-07-12T12:21:29.676Z - error: Error: ENOTDIR: not a directory, watch '/home/victor/ungit-electron/src/ungit-linux-x64/resources/app.asar/assets'
    at FSWatcher.<computed> (node:internal/fs/watchers:244:19)
    at Object.watch (node:fs:2251:34)
    at /home/victor/ungit-electron/ungit-linux-x64/resources/app.asar/node_modules/node-watch/lib/watch.js:398:22
    at hasNativeRecursive (/home/victor/ungit-electron/ungit-linux-x64/resources/app.asar/node_modules/node-watch/lib/has-native-recursive.js:61:12)
    at Watcher.watchDirectory (/home/victor/ungit-electron/ungit-linux-x64/resources/app.asar/node_modules/node-watch/lib/watch.js:381:3)
    at /home/victor/ungit-electron/ungit-linux-x64/resources/app.asar/node_modules/node-watch/lib/watch.js:414:16
    at /home/victor/ungit-electron/ungit-linux-x64/resources/app.asar/node_modules/node-watch/lib/watch.js:143:35
    at Array.forEach (<anonymous>)
    at /home/victor/ungit-electron/ungit-linux-x64/resources/app.asar/node_modules/node-watch/lib/watch.js:141:13
    at node:electron/js2c/asar_bundle:5:461

It seems to believe app.asar is a directory, which as an assets subdirectory, while it's a file

Reproduce

  1. Download and extract ungit's latest release
  2. Try to open the parent folder containing the extracted release, with ungit electron

Simple Linux command for the above

mkdir test && cd test && wget 'https://github.com/FredrikNoren/ungit/releases/download/v1.5.21/ungit-1.5.21-linux-x64.zip' && unzip ungit-1.5.21-linux-x64.zip && ungit-linux-x64/ungit
campersau commented 2 years ago

electron monkey patches the fs APIs to transparently support reading files from asar archives (asar is similar to zip) which interfers with node-watch.

Related upstream bug https://github.com/yuanchuan/node-watch/issues/108