From adf7e17fce4fbbbb86b5bdc15aabb84579fdaeed Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 13 Nov 2014 15:09:10 -0800 Subject: [PATCH] Use spawn instead of execFile --- src/browser/auto-updater-win32.coffee | 31 ++++++++++++++++----------- src/browser/squirrel-events.coffee | 1 + 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/browser/auto-updater-win32.coffee b/src/browser/auto-updater-win32.coffee index e45ad81fb..a28a8092e 100644 --- a/src/browser/auto-updater-win32.coffee +++ b/src/browser/auto-updater-win32.coffee @@ -17,25 +17,33 @@ class AutoUpdater # Schedule an update when the feed URL is set process.nextTick => @checkForUpdates() + spawnUpdate: (args, callback) -> + stdout = '' + error = null + updateProcess = ChildProcess.spawn(@updateDotExe, args) + updateProcess.stdout.on 'data', (data) -> stdout += data + updateProcess.on 'error', (processError) -> error ?= processError + updateProcess.on 'close', (code, signal) -> + error ?= new Error("Command failed: #{signal}") if code isnt 0 + error?.code ?= code + error?.stdout ?= stdout + callback(error, stdout) + undefined + quitAndInstall: -> unless fs.existsSync(@updateDotExe) shellAutoUpdater.quitAndInstall() return - args = ['--update', @updateUrl] - ChildProcess.execFile @updateDotExe, args, (error) -> + @spawn ['--update', @updateUrl], (error) => return if error? - args = ['--processStart', 'atom.exe'] - ChildProcess.execFile @updateDotExe, args, -> + @spawn ['--processStart', 'atom.exe'], -> shellAutoUpdater.quitAndInstall() downloadUpdate: (callback) -> - args = ['--download', @updateUrl] - ChildProcess.execFile @updateDotExe, args, (error, stdout) -> - if error? - error.stdout = stdout - return callback(error) + @spawn ['--download', @updateUrl], (error, stdout) -> + return callback(error) if error? try # Last line of output is the JSON details about the releases @@ -48,10 +56,7 @@ class AutoUpdater callback(null, update) installUpdate: (callback) -> - args = ['--update', @updateUrl] - ChildProcess.execFile @updateDotExe, args, (error, stdout) -> - error?.stdout = stdout - callback(error) + @spawn(['--update', @updateUrl], callback) checkForUpdates: -> throw new Error('Update URL is not set') unless @updateUrl diff --git a/src/browser/squirrel-events.coffee b/src/browser/squirrel-events.coffee index 82830c5ee..4725cf7f5 100644 --- a/src/browser/squirrel-events.coffee +++ b/src/browser/squirrel-events.coffee @@ -8,6 +8,7 @@ spawnUpdateAndQuit = (option) -> updateProcess = ChildProcess.spawn(updateDotExe, ["--#{option}", exeName]) updateProcess.on 'error', -> # Ignore errors updateProcess.on 'close', -> app.quit() + undefined module.exports = -> switch process.argv[1]