@@ -8,6 +8,7 @@ FileRecoveryService = require './file-recovery-service'
88ipcHelpers = require ' ../ipc-helpers'
99{BrowserWindow , Menu , app , dialog , ipcMain , shell , screen } = require ' electron'
1010{CompositeDisposable , Disposable } = require ' event-kit'
11+ crypto = require ' crypto'
1112fs = require ' fs-plus'
1213path = require ' path'
1314os = require ' os'
@@ -33,11 +34,19 @@ class AtomApplication
3334 # Public: The entry point into the Atom application.
3435 @ open: (options ) ->
3536 unless options .socketPath ?
37+ username = if process .platform is ' win32' then process .env .USERNAME else process .env .USER
38+ # Lowercasing the ATOM_HOME to make sure that we don't get multiple sockets
39+ # on case-insensitive filesystems due to arbitrary case differences in paths.
40+ atomHomeUnique = path .resolve (process .env .ATOM_HOME ).toLowerCase ()
41+ hash = crypto .createHash (' sha1' ).update (options .version ).update (' |' ).update (process .arch ).update (' |' ).update (username).update (' |' ).update (atomHomeUnique)
42+ # We only keep the first 12 characters of the hash as not to have excessively long
43+ # socket file. Note that macOS/BSD limit the length of socket file paths (see #15081).
44+ # The replace calls convert the digest into "URL and Filename Safe" encoding (see RFC 4648).
45+ atomInstanceDigest = hash .digest (' base64' ).substring (0 , 12 ).replace (/ \+ / g , ' -' ).replace (/ \/ / g , ' _' )
3646 if process .platform is ' win32'
37- userNameSafe = new Buffer (process .env .USERNAME ).toString (' base64' )
38- options .socketPath = " \\\\ .\\ pipe\\ atom-#{ options .version } -#{ userNameSafe} -#{ process .arch } -sock"
47+ options .socketPath = " \\\\ .\\ pipe\\ atom-#{ atomInstanceDigest} -sock"
3948 else
40- options .socketPath = path .join (os .tmpdir (), " atom-#{ options . version } - #{ process . env . USER } .sock" )
49+ options .socketPath = path .join (os .tmpdir (), " atom-#{ atomInstanceDigest } .sock" )
4150
4251 # FIXME: Sometimes when socketPath doesn't exist, net.connect would strangely
4352 # take a few seconds to trigger 'error' event, it could be a bug of node
0 commit comments