Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOs: Fail to delete .asar files. #106

Open
joshuef opened this issue Aug 15, 2019 · 6 comments
Open

MacOs: Fail to delete .asar files. #106

joshuef opened this issue Aug 15, 2019 · 6 comments

Comments

@joshuef
Copy link

joshuef commented Aug 15, 2019

Attempting to use del to remove .app files of electron apps fails with ENOTEMPTY for .asar files only.

Currently I'm working around this manually invoking rm on mac for those files prior to a full del on the target app file. I assume it's something to do with .asar files being treated somewhat as folder on Mac?

(I havent tested the behaviour on other platforms as yet).

@sindresorhus
Copy link
Owner

Can you include the error stack trace?

@sindresorhus
Copy link
Owner

I assume it's something to do with .asar files being treated somewhat as folder on Mac?

No, .asar is a binary on all platforms.

@meness
Copy link

meness commented Feb 9, 2020

I think it fails to delete files that their names start with a dot (for instance: .gitignore, .env). I also have the same problem on Windows while using the latest version.

@pascalbayer
Copy link

As requested I want to add some more context to the issue.
First of all the issue only occurs while executing del within an electron application trying to delete another .app file that contains any .asar file. Running del against the same file from a normal nodejs process works absolutely fine.
I wasn't able to get any stack trace for the issue but the exact error message is ENOTEMPTY: directory not empty, rmdir '/dist/executables/mac/myapp.app/Contents/Resources' which is the directory that contains the .asar file.
I'm just guessing but it might be related to electron treating .asar files in a specific way and maybe locking these files or unpacking them automatically

@pascalbayer
Copy link

After writing the lines above I was able to find the solution in the electron docs which state that With special patches in Electron, Node APIs like fs.readFile and require treat asar archives as virtual directories, and the files in it as normal files in the filesystem.
However, there is also a section in the docs explaining how to disable this special treatment of asar files: Treating an asar Archive as a Normal File.

I was able to get everything working with the following lines:

process.noAsar = true;
await del(pathToExecutable, {
    force: true
});
process.noAsar = false;

@rahul-dutt-sharma
Copy link

life saver!

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

No branches or pull requests

5 participants