Skip to content

Commit

Permalink
fix(nsis): output files sometimes locked by virus scanners (#5005) (#…
Browse files Browse the repository at this point in the history
…5143)

Co-authored-by: Bernd <[email protected]>
  • Loading branch information
berkon and Bernd authored Jul 27, 2020
1 parent 34d1752 commit a6d00ab
Showing 1 changed file with 29 additions and 0 deletions.
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

0 comments on commit a6d00ab

Please sign in to comment.