Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d620da3
Enable Portable Mode
anaisbetts Aug 19, 2015
4a53619
Patch the browser process too
anaisbetts Sep 7, 2015
4775595
Correctly handle devMode
anaisbetts Sep 7, 2015
2f6b678
Merge remote-tracking branch 'atom/master'
raelyard Oct 5, 2015
f067fdb
Merge branch 'master' into portable-mode
raelyard Oct 6, 2015
b8a1537
Implement Portable Mode
raelyard Oct 9, 2015
db57479
Remove superfluous check on ATOM_HOME
raelyard Oct 9, 2015
28c322a
Fix broken focused suite in spec
raelyard Oct 9, 2015
4312f76
Added command line parameter to set portable
raelyard Oct 13, 2015
16c2391
Add notification if Portable Home not writable
raelyard Oct 14, 2015
265ee01
Clean convention inconsistencies for portable mode
raelyard Oct 15, 2015
28a1bbf
Fix function names - consistent with convention
raelyard Oct 15, 2015
ef71211
Always include portable home path in warning
raelyard Oct 15, 2015
bcfb6ab
Remove explicit returns
raelyard Oct 15, 2015
82f5e81
Restore check on ATOM_HOME
raelyard Oct 16, 2015
03faddd
Undo add command line parameter to set portable
raelyard Oct 16, 2015
6d4105a
Escape characters is portable path not writable
raelyard Oct 20, 2015
8652890
Simplify markdown escaping for warning
raelyard Oct 20, 2015
e0697ec
Merge branch 'master' into portable-mode
raelyard Oct 21, 2015
e93b013
Remove unused function parameter
raelyard Oct 21, 2015
810f0e4
Fix merge problem and missing function call
raelyard Oct 21, 2015
3534589
Fix function name to be consistent with convention
raelyard Oct 22, 2015
8acb2af
Remove unused parameter
raelyard Oct 22, 2015
b1d10ef
Revert moving parse of command line
raelyard Oct 22, 2015
02fe2cf
:art:
kevinsawicki Oct 27, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions spec/atom-portable-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
path = require "path"
fs = require 'fs-plus'
temp = require "temp"
rimraf = require "rimraf"
AtomPortable = require "../src/browser/atom-portable"

describe "Check for Portable Mode", ->
describe "Windows", ->
describe "with ATOM_HOME environment variable", ->
it "returns false", ->
expect(AtomPortable.isPortableInstall("win32", "C:\\some\\path")).toBe false

describe "without ATOM_HOME environment variable", ->
environmentAtomHome = undefined
portableAtomHomePath = path.join(path.dirname(process.execPath), "..", ".atom")
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("win32", environmentAtomHome)).toBe true

describe "without .atom directory sibling to exec", ->
beforeEach ->
rimraf.sync(portableAtomHomePath) if fs.existsSync(portableAtomHomePath)

it "returns false", ->
expect(AtomPortable.isPortableInstall("win32", environmentAtomHome)).toBe false

describe "Mac", ->
it "returns false", ->
expect(AtomPortable.isPortableInstall("darwin", "darwin")).toBe false

describe "Linux", ->
it "returns false", ->
expect(AtomPortable.isPortableInstall("linux", "linux")).toBe false
10 changes: 10 additions & 0 deletions src/atom-environment.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
crypto = require 'crypto'
path = require 'path'
ipc = require 'ipc'

_ = require 'underscore-plus'
{deprecate} = require 'grim'
Expand Down Expand Up @@ -203,6 +204,15 @@ class AtomEnvironment extends Model

@observeAutoHideMenuBar()

checkPortableHomeWritable = ->
responseChannel = "check-portable-home-writable-response"
ipc.on responseChannel, (response) ->
ipc.removeAllListeners(responseChannel)
atom.notifications.addWarning("#{response.message.replace(/([\\\.+\\-_#!])/g, '\\$1')}") if not response.writable
ipc.send('check-portable-home-writable', responseChannel)

checkPortableHomeWritable()

setConfigSchema: ->
@config.setSchema null, {type: 'object', properties: _.clone(require('./config-schema'))}

Expand Down
32 changes: 32 additions & 0 deletions src/browser/atom-portable.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
fs = require 'fs-plus'
path = require 'path'
ipc = require 'ipc'

module.exports =
class AtomPortable
@getPortableAtomHomePath: ->
execDirectoryPath = path.dirname(process.execPath)
path.join(execDirectoryPath, '..', '.atom')

@isPortableInstall: (platform, environmentAtomHome, defaultHome) ->
return false unless platform is 'win32'
return false if environmentAtomHome
return false if not fs.existsSync(@getPortableAtomHomePath())
# currently checking only that the directory exists and is writable,
# probably want to do some integrity checks on contents in future
@isPortableAtomHomePathWritable(defaultHome)

@isPortableAtomHomePathWritable: (defaultHome) ->
writable = false
message = ""
try
writePermissionTestFile = path.join(@getPortableAtomHomePath(), "write.test")
fs.writeFileSync(writePermissionTestFile, "test") if not fs.existsSync(writePermissionTestFile)
fs.removeSync(writePermissionTestFile)
writable = true
catch error
message = "Failed to use portable Atom home directory (#{@getPortableAtomHomePath()}). Using the default instead (#{defaultHome}). #{error.message}"

ipc.on 'check-portable-home-writable', (event) ->
event.sender.send 'check-portable-home-writable-response', {writable, message}
writable
2 changes: 2 additions & 0 deletions src/browser/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ setupCrashReporter = ->
setupAtomHome = ->
return if process.env.ATOM_HOME
atomHome = path.join(app.getHomeDir(), '.atom')
AtomPortable = require './atom-portable'
atomHome = AtomPortable.getPortableAtomHomePath() if AtomPortable.isPortableInstall(process.platform, process.env.ATOM_HOME, atomHome)
try
atomHome = fs.realpathSync(atomHome)
process.env.ATOM_HOME = atomHome
Expand Down
2 changes: 2 additions & 0 deletions static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
})

// Ensure ATOM_HOME is always set before anything else is required
// This is because of a difference in Linux not inherited between browser and render processes
// issue #5142
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

setupAtomHome()

// Normalize to make sure drive letter case is consistent on Windows
Expand Down