From 2f5a99fac21a03b95dcd1dc0814d6280ad2d2f84 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 23 Apr 2013 11:03:55 -0700 Subject: [PATCH] Install atom command asynchronously --- spec/app/window-spec.coffee | 8 ++++++-- src/app/window.coffee | 20 ++++++++++++++------ src/stdlib/fs-utils.coffee | 7 +++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/spec/app/window-spec.coffee b/spec/app/window-spec.coffee index b93d7abbf..977d628e1 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -165,8 +165,12 @@ describe "Window", -> it "copies atom.sh to the specified path", -> expect(fsUtils.exists(commandPath)).toBeFalsy() window.installAtomCommand(commandPath) - expect(fsUtils.exists(commandPath)).toBeTruthy() - expect(fsUtils.read(commandPath).length).toBeGreaterThan 1 + + waitsFor -> + fsUtils.exists(commandPath) + + runs -> + expect(fsUtils.read(commandPath).length).toBeGreaterThan 1 describe ".deserialize(state)", -> class Foo diff --git a/src/app/window.coffee b/src/app/window.coffee index 508cf0dda..12a29a28e 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -72,13 +72,21 @@ window.shutdown = -> window.project = null window.git = null -window.installAtomCommand = (commandPath) -> - return if fsUtils.exists(commandPath) +window.installAtomCommand = (commandPath, done) -> + fs.exists commandPath, (exists) -> + return if exists - bundledCommandPath = fsUtils.resolve(window.resourcePath, 'atom.sh') - if bundledCommandPath? - fsUtils.write(commandPath, fsUtils.read(bundledCommandPath)) - fs.chmod(commandPath, 0o755, commandPath) + bundledCommandPath = fsUtils.resolve(window.resourcePath, 'atom.sh') + if bundledCommandPath? + fs.readFile bundledCommandPath, (error, data) -> + if error? + console.warn "Failed to install `atom` binary", error + else + fsUtils.writeAsync commandPath, data, (error) -> + if error? + console.warn "Failed to install `atom` binary", error + else + fs.chmod(commandPath, 0o755, commandPath) window.handleWindowEvents = -> $(window).command 'window:toggle-full-screen', => atom.toggleFullScreen() diff --git a/src/stdlib/fs-utils.coffee b/src/stdlib/fs-utils.coffee index 8fc11d36a..d3e46ec44 100644 --- a/src/stdlib/fs-utils.coffee +++ b/src/stdlib/fs-utils.coffee @@ -155,6 +155,13 @@ module.exports = mkdirp.sync(@directory(path)) fs.writeFileSync(path, content) + writeAsync: (path, content, callback) -> + mkdirp @directory(path), (error) -> + if error? + callback?(error) + else + fs.writeFile(path, content, callback) + makeDirectory: (path) -> fs.mkdirSync(path)