`Command failed: cp -R` during `postMake` hook building `dmg` if there's a `dmg` mounted already
Pre-flight checklist
- [X] I have read the contribution documentation for this project.
- [X] I agree to follow the code of conduct that this project uses.
- [X] I have searched the issue tracker for a bug that matches the one I want to file, without success.
Electron Forge version
6.4.2
Electron version
v27.0.0
Operating system
macOS 13.5.2 (22G91)
Last known working Electron Forge version
No response
Expected behavior
If you have a .dmg for your app mounted, it should automatically be un-mounted when building a new .dmg.
Or, electron-forge could give a nice error message telling you to un-mount it first.
Actual behavior
electron-forge make fails during the postMake hook while building a .dmg file if you have an older .dmg with the same name mounted already.
It's worth noting that the .zip builds successfully and runs just fine. This is only the .dmg maker that's failing.
An unhandled rejection has occurred inside Forge:
Error: Command failed: cp -R /path/to/my/electron/app/out/MY APP NAME-darwin-arm64/MY APP NAME.app /Volumes/MY APP NAME 1/MY APP NAME.app
cp: /Volumes/MY APP NAME 1/MY APP NAME.app: Operation not permitted
(there are a couple hundred errors like the above, for each file.....)
at makeError (/path/to/my/electron/app/node_modules/execa/index.js:174:9)
at /path/to/my/electron/app/node_modules/execa/index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:95:5)
ELIFECYCLE Command failed with exit code 1.
Steps to reproduce
Add maker-dmg and maker-zip to your forge.config.ts...
import { MakerDMG } from "@electron-forge/maker-dmg";
import { MakerZIP } from "@electron-forge/maker-zip";
//...
makers: [
new MakerZIP(),
new MakerDMG(
{
icon: "./images/[email protected]",
name: "MY APP NAME",
overwrite: true,
},
["darwin"],
),
]
- Run
electron-forge maketo generate a.dmgfile. - Mount the
.dmgfile as a volume- It will be at
/Volumes/YOUR APP NAME
- It will be at
- Run
electron-forge makeagain, it will fail duringpostMake
Additional information
No response
That's kind of expected IMO, the same thing happens on Windows when you're running your app straight out of the out directory and try to package it again — the .exe file will be locked and the operation will fail.
Or, electron-forge could give a nice error message telling you to un-mount it first.
The "operation not permitted" error is a pretty generic one, I'm not sure if there's a way to tell whether it's occurring because the .dmg is mounted or something else, like not having write access to the out directory, for example.
It the maker knows the volume that it would mount the DMG to, maybe there's a way it could detect that it's already mounted before trying to create it? I haven't looked at the code that actually does this so I have no idea how hard that would be 😅
Agreed with @erikian's take above. Would accept a PR fixing this issue but will close as a wontfix IMO because this is more of a system issue.