I have an asar file that is read from an electron app. From the same app, I want to delete this asar file, however I keep getting an EBUSY error. I have found only two places where this asar file is read:
A file protocol. It reads a file that is in the asar.Did some debugging and found out that this isn't causing it to lockfoo://fileinasar.js
for example.fileinasar.js
is a file that was packed into the asar. In order to run this file, it is done byimport("foo://fileinasar.js")
. This import is stored in an object, but when I do delete this object property, it still locks. (this file is run in renderer)- Or in the main process when I use
fs/promises
toreadFile
the samefileinasar.js
file. However, this is only used once and I don't think it should be able to lock it while the project is running. However,readFile
should automatically close the file anyway.
These are the only two ways the asar file is read in my project. Neither seem like they should lock it long term.
I have no idea how to unlock the asar package. I found several other potential solutions online, however none helped, or they said to use original-fs
, which I want to try to avoid. I have also tried electron/asar
's uncache
and uncacheAll
but that also didn't unlink the file.
How can I unlock the asar so that I can delete it in the same project? This is using electron ^21.2.0 and only happens on windows (I'm not deleting the anti-malware to solve this).
Edit: When I try using the spawn
"hack" that @Anonymoose provided, I get this
When I try the alternative unlink
method, I get this