diff --git a/spec/atom-portable-spec.coffee b/spec/atom-portable-spec.coffee new file mode 100644 index 000000000..f5b24a4a1 --- /dev/null +++ b/spec/atom-portable-spec.coffee @@ -0,0 +1,52 @@ +path = require "path" +fs = require 'fs-plus' +temp = require "temp" +rimraf = require "rimraf" +AtomPortable = require "../src/browser/atom-portable" + +fdescribe "Portable Mode", -> + describe "Windows", -> + platform = "win32" + + describe "with ATOM_HOME environment variable", -> + environmentAtomHome = "C:\\some\\path" + it "returns false", -> + expect(AtomPortable.isPortableInstall(platform, environmentAtomHome)).toBe false + + describe "without ATOM_HOME environment variable", -> + environmentAtomHome = undefined + portableAtomHomePath = path.join(path.dirname(process.execPath), "../.atom").toString() + portableAtomHomeNaturallyExists = fs.existsSync(portableAtomHomePath) + portableAtomHomeBackupPath = portableAtomHomePath + ".temp" + + beforeEach -> + fs.renameSync(portableAtomHomePath, portableAtomHomeBackupPath) if fs.existsSync(portableAtomHomePath) + + afterEach -> + if portableAtomHomeNaturallyExists + fs.renameSync(portableAtomHomeBackupPath, portableAtomHomePath) if not fs.existsSync(portableAtomHomePath) + else + rimraf.sync(portableAtomHomePath) if fs.existsSync(portableAtomHomePath) + rimraf.sync(portableAtomHomeBackupPath) if fs.existsSync(portableAtomHomeBackupPath) + + describe "with .atom directory sibling to exec", -> + beforeEach -> + fs.mkdirSync(portableAtomHomePath) if not fs.existsSync(portableAtomHomePath) + it "returns true", -> + expect(AtomPortable.isPortableInstall(platform, environmentAtomHome)).toBe true + + describe "without .atom directory sibling to exec", -> + beforeEach -> + rimraf.sync(portableAtomHomePath) if fs.existsSync(portableAtomHomePath) + it "returns false", -> + expect(AtomPortable.isPortableInstall(platform, environmentAtomHome)).toBe false + + describe "Mac", -> + platform = "darwin" + it "returns false", -> + expect(AtomPortable.isPortableInstall(platform, platform)).toBe false + + describe "Linux", -> + platform = "linux" + it "returns false", -> + expect(AtomPortable.isPortableInstall(platform, platform)).toBe false diff --git a/src/browser/atom-portable.coffee b/src/browser/atom-portable.coffee new file mode 100644 index 000000000..2a8e4d7a0 --- /dev/null +++ b/src/browser/atom-portable.coffee @@ -0,0 +1,15 @@ +fs = require 'fs-plus' +path = require 'path' + +module.exports = +class AtomPortable + @portableAtomHomePath: -> + execDirectoryPath = path.dirname(process.execPath) + return path.join(execDirectoryPath, "../.atom") + @isPortableInstall: (platform, environmentAtomHome) -> + return false unless platform is 'win32' + return false if environmentAtomHome + + # currently checking only that the directory exists, probably want to do + # some integrity checks on contents and make sure it's writable in future + return fs.existsSync(@portableAtomHomePath()) diff --git a/src/browser/main.coffee b/src/browser/main.coffee index cfac6f34c..1db0b87e7 100644 --- a/src/browser/main.coffee +++ b/src/browser/main.coffee @@ -57,23 +57,13 @@ handleStartupEventWithSquirrel = -> setupCrashReporter = -> crashReporter.start(productName: 'Atom', companyName: 'GitHub') -isPortableInstall = (args) -> - return false unless process.platform is 'win32' - return false unless (process and process.type) - return false if args.devMode or args.testMode - - ourPath = process.execPath.toLowerCase() - return (ourPath.indexOf(process.env.LOCALAPPDATA.toLowerCase()) is 0) - setupAtomHome = (args) -> return if process.env.ATOM_HOME - atomHome = path.join(app.getHomeDir(), '.atom') - try - atomHome = fs.realpathSync(atomHome) - fs.statSync(atomHome) - catch - atomHome = path.join(path.dirname(process.execPath), '.atom') if isPortableInstall(args) + AtomPortable = require './atom-portable' + atomHome = AtomPortable.portableAtomHomePath() if AtomPortable.isPortableInstall process.platform, process.env.ATOM_HOME + atomHome = fs.realpathSync(atomHome) + fs.statSync(atomHome) process.env.ATOM_HOME = atomHome