mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-23 23:54:13 +08:00
fix(launch): Do not create global symlinks to N1
and apm
. Closes #1553
This commit is contained in:
parent
2a7a97eebc
commit
025d4b4081
3 changed files with 0 additions and 166 deletions
|
@ -1,75 +0,0 @@
|
||||||
import CommandInstaller from '../src/command-installer'
|
|
||||||
import fs from 'fs-plus'
|
|
||||||
|
|
||||||
describe("CommandInstaller", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
this.resourcePath = "/resourcePath";
|
|
||||||
this.callback = jasmine.createSpy('callback')
|
|
||||||
|
|
||||||
spyOn(CommandInstaller, "symlinkCommand").andCallFake((sourcePath, destinationPath, callback) => {
|
|
||||||
callback()
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Installs N1 if it doesn't already exist", () => {
|
|
||||||
spyOn(fs, "readlink").andCallFake((path, fn) => {
|
|
||||||
expect(path).toBe("/usr/local/bin/N1")
|
|
||||||
fn(new Error("not found"), undefined)
|
|
||||||
})
|
|
||||||
CommandInstaller.installN1Command(this.resourcePath, false, this.callback)
|
|
||||||
expect(CommandInstaller.symlinkCommand).toHaveBeenCalled()
|
|
||||||
expect(this.callback).toHaveBeenCalled()
|
|
||||||
expect(this.callback.calls[0].args[0]).toBeUndefined()
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Leaves the N1 link alone if exists and is already correct", () => {
|
|
||||||
spyOn(fs, "readlink").andCallFake((path, fn) => {
|
|
||||||
expect(path).toBe("/usr/local/bin/N1")
|
|
||||||
fn(null, this.resourcePath + "/N1.sh")
|
|
||||||
})
|
|
||||||
CommandInstaller.installN1Command(this.resourcePath, false, this.callback)
|
|
||||||
expect(CommandInstaller.symlinkCommand).not.toHaveBeenCalled()
|
|
||||||
expect(this.callback).toHaveBeenCalled()
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Overrides the N1 link if it exists but is not correct", () => {
|
|
||||||
spyOn(fs, "readlink").andCallFake((path, fn) => {
|
|
||||||
expect(path).toBe("/usr/local/bin/N1")
|
|
||||||
fn(null, this.resourcePath + "/totally/wrong/path")
|
|
||||||
})
|
|
||||||
CommandInstaller.installN1Command(this.resourcePath, false, this.callback)
|
|
||||||
expect(CommandInstaller.symlinkCommand).toHaveBeenCalled()
|
|
||||||
expect(this.callback).toHaveBeenCalled()
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Installs apm if it doesn't already exist", () => {
|
|
||||||
spyOn(fs, "readlink").andCallFake((path, fn) => {
|
|
||||||
expect(path).toBe("/usr/local/bin/apm")
|
|
||||||
fn(new Error("not found"), undefined)
|
|
||||||
})
|
|
||||||
CommandInstaller.installApmCommand(this.resourcePath, false, this.callback)
|
|
||||||
expect(CommandInstaller.symlinkCommand).toHaveBeenCalled()
|
|
||||||
expect(this.callback).toHaveBeenCalled()
|
|
||||||
expect(this.callback.calls[0].args[0]).toBeUndefined()
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Leaves the apm link alone if exists and is already correct", () => {
|
|
||||||
spyOn(fs, "readlink").andCallFake((path, fn) => {
|
|
||||||
expect(path).toBe("/usr/local/bin/apm")
|
|
||||||
fn(null, this.resourcePath + "/apm/node_modules/.bin/apm")
|
|
||||||
})
|
|
||||||
CommandInstaller.installApmCommand(this.resourcePath, false, this.callback)
|
|
||||||
expect(CommandInstaller.symlinkCommand).not.toHaveBeenCalled()
|
|
||||||
expect(this.callback).toHaveBeenCalled()
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Leaves the apm link alone it exists and is not correct since it likely refers to Atom's apm", () => {
|
|
||||||
spyOn(fs, "readlink").andCallFake((path, fn) => {
|
|
||||||
expect(path).toBe("/usr/local/bin/apm")
|
|
||||||
fn(null, this.resourcePath + "/pointing/to/Atom/apm")
|
|
||||||
})
|
|
||||||
CommandInstaller.installApmCommand(this.resourcePath, false, this.callback)
|
|
||||||
expect(CommandInstaller.symlinkCommand).not.toHaveBeenCalled()
|
|
||||||
expect(this.callback).toHaveBeenCalled()
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,82 +0,0 @@
|
||||||
path = require 'path'
|
|
||||||
_ = require 'underscore'
|
|
||||||
async = require 'async'
|
|
||||||
fs = require 'fs-plus'
|
|
||||||
mkdirp = require 'mkdirp'
|
|
||||||
runas = require 'runas'
|
|
||||||
|
|
||||||
module.exports =
|
|
||||||
getInstallDirectory: ->
|
|
||||||
"/usr/local/bin"
|
|
||||||
|
|
||||||
installShellCommandsInteractively: ->
|
|
||||||
showErrorDialog = (error) ->
|
|
||||||
NylasEnv.confirm
|
|
||||||
message: "Failed to install shell commands"
|
|
||||||
detailedMessage: error.message
|
|
||||||
|
|
||||||
resourcePath = NylasEnv.getLoadSettings().resourcePath
|
|
||||||
@installN1Command resourcePath, true, (error) =>
|
|
||||||
if error?
|
|
||||||
showErrorDialog(error)
|
|
||||||
else
|
|
||||||
@installApmCommand resourcePath, true, (error) ->
|
|
||||||
if error?
|
|
||||||
showErrorDialog(error)
|
|
||||||
else
|
|
||||||
NylasEnv.confirm
|
|
||||||
message: "Commands installed."
|
|
||||||
detailedMessage: "The shell commands `n1` and `apm` are installed."
|
|
||||||
|
|
||||||
installN1Command: (resourcePath, askForPrivilege, callback) ->
|
|
||||||
commandPath = path.join(resourcePath, 'N1.sh')
|
|
||||||
@createSymlink commandPath, askForPrivilege, callback, {override: true}
|
|
||||||
|
|
||||||
installApmCommand: (resourcePath, askForPrivilege, callback) ->
|
|
||||||
commandPath = path.join(resourcePath, 'apm', 'node_modules', '.bin', 'apm')
|
|
||||||
@createSymlink commandPath, askForPrivilege, callback, {override: false}
|
|
||||||
|
|
||||||
createSymlink: (commandPath, askForPrivilege, callback, {override}) ->
|
|
||||||
return unless process.platform is 'darwin'
|
|
||||||
|
|
||||||
commandName = path.basename(commandPath, path.extname(commandPath))
|
|
||||||
destinationPath = path.join(@getInstallDirectory(), commandName)
|
|
||||||
|
|
||||||
fs.readlink destinationPath, (error, realpath) =>
|
|
||||||
if realpath is commandPath
|
|
||||||
callback()
|
|
||||||
return
|
|
||||||
else if realpath and realpath isnt commandPath and not override
|
|
||||||
callback()
|
|
||||||
return
|
|
||||||
else
|
|
||||||
@symlinkCommand commandPath, destinationPath, (error) =>
|
|
||||||
if askForPrivilege and error?.code is 'EACCES'
|
|
||||||
try
|
|
||||||
error = null
|
|
||||||
@symlinkCommandWithPrivilegeSync(commandPath, destinationPath)
|
|
||||||
catch error
|
|
||||||
|
|
||||||
callback?(error)
|
|
||||||
|
|
||||||
symlinkCommand: (sourcePath, destinationPath, callback) ->
|
|
||||||
fs.unlink destinationPath, (error) ->
|
|
||||||
if error? and error?.code != 'ENOENT'
|
|
||||||
callback(error)
|
|
||||||
else
|
|
||||||
mkdirp path.dirname(destinationPath), (error) ->
|
|
||||||
if error?
|
|
||||||
callback(error)
|
|
||||||
else
|
|
||||||
fs.symlink sourcePath, destinationPath, callback
|
|
||||||
|
|
||||||
symlinkCommandWithPrivilegeSync: (sourcePath, destinationPath) ->
|
|
||||||
if runas('/bin/rm', ['-f', destinationPath], admin: true) != 0
|
|
||||||
throw new Error("Failed to remove '#{destinationPath}'")
|
|
||||||
|
|
||||||
if runas('/bin/mkdir', ['-p', path.dirname(destinationPath)], admin: true) != 0
|
|
||||||
throw new Error("Failed to create directory '#{destinationPath}'")
|
|
||||||
|
|
||||||
if runas('/bin/ln', ['-s', sourcePath, destinationPath], admin: true) != 0
|
|
||||||
throw new Error("Failed to symlink '#{sourcePath}' to '#{destinationPath}'")
|
|
||||||
|
|
|
@ -674,7 +674,6 @@ class NylasEnvConstructor extends Model
|
||||||
window.requestAnimationFrame =>
|
window.requestAnimationFrame =>
|
||||||
@displayWindow() unless initializeInBackground
|
@displayWindow() unless initializeInBackground
|
||||||
|
|
||||||
@registerCommands()
|
|
||||||
@loadConfig()
|
@loadConfig()
|
||||||
@keymaps.loadBundledKeymaps()
|
@keymaps.loadBundledKeymaps()
|
||||||
@themes.loadBaseStylesheets()
|
@themes.loadBaseStylesheets()
|
||||||
|
@ -696,14 +695,6 @@ class NylasEnvConstructor extends Model
|
||||||
@restoreWindowDimensions()
|
@restoreWindowDimensions()
|
||||||
@getCurrentWindow().setMinimumSize(875, 250)
|
@getCurrentWindow().setMinimumSize(875, 250)
|
||||||
|
|
||||||
registerCommands: ->
|
|
||||||
{resourcePath} = @getLoadSettings()
|
|
||||||
CommandInstaller = require './command-installer'
|
|
||||||
CommandInstaller.installN1Command resourcePath, false, (error) ->
|
|
||||||
console.warn error.message if error?
|
|
||||||
CommandInstaller.installApmCommand resourcePath, false, (error) ->
|
|
||||||
console.warn error.message if error?
|
|
||||||
|
|
||||||
# Call this method when establishing a secondary application window
|
# Call this method when establishing a secondary application window
|
||||||
# displaying a specific set of packages.
|
# displaying a specific set of packages.
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue