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

fix(nsis): output files sometimes locked by virus scanners (#5005) #5143

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,35 @@ export class NsisTarget extends Target {

const nsisPath = await NSIS_PATH()
const command = path.join(nsisPath, process.platform === "darwin" ? "mac" : (process.platform === "win32" ? "Bin" : "linux"), process.platform === "win32" ? "makensis.exe" : "makensis")

// Fix for an issue caused by virus scanners, locking the file during write
// https://github.com/electron-userland/electron-builder/issues/5005
let ensureNotBusy = new Promise ( resolve => {
let fs = require ('fs')
let outFile = commands['OutFile'].replace(/\"/g, "")

var isBusy = async(wasBusyBefore) => {
fs.open(outFile, 'r+', async (err, fd) => {
if (err && err.code === 'EBUSY') {
if (!wasBusyBefore)
_builderUtil().log.info( {}, "output file is locked for writing (maybe by virus scanner) => waiting for unlock ...")

await new Promise(resolve => setTimeout(resolve, 2000))
isBusy(true)
} else {
if (fd !== undefined)
fs.close(fd)

resolve()
}
})
}

isBusy()
})

await ensureNotBusy

await spawnAndWrite(command, args, script, {
// we use NSIS_CONFIG_CONST_DATA_PATH=no to build makensis on Linux, but in any case it doesn't use stubs as MacOS/Windows version, so, we explicitly set NSISDIR
env: {...process.env, NSISDIR: nsisPath},
Expand Down