Skip to content

Commit 1964b00

Browse files
committed
Make socketPath shorter
To work around the limited socket file length on macOS/BSD.
1 parent 2b3e22a commit 1964b00

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main-process/atom-application.coffee

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ class AtomApplication
3838
# Lowercasing the ATOM_HOME to make sure that we don't get multiple sockets
3939
# on case-insensitive filesystems due to arbitrary case differences in paths.
4040
atomHomeUnique = path.resolve(process.env.ATOM_HOME).toLowerCase()
41-
hash = crypto.createHash('sha1').update(username).update('|').update(atomHomeUnique)
42-
atomInstanceDigest = hash.digest('hex').substring(0, 32)
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, '_')
4346
if process.platform is 'win32'
44-
options.socketPath = "\\\\.\\pipe\\atom-#{options.version}-#{process.arch}-#{atomInstanceDigest}-sock"
47+
options.socketPath = "\\\\.\\pipe\\atom-#{atomInstanceDigest}-sock"
4548
else
46-
options.socketPath = path.join(os.tmpdir(), "atom-#{options.version}-#{process.arch}-#{atomInstanceDigest}.sock")
49+
options.socketPath = path.join(os.tmpdir(), "atom-#{atomInstanceDigest}.sock")
4750

4851
# FIXME: Sometimes when socketPath doesn't exist, net.connect would strangely
4952
# take a few seconds to trigger 'error' event, it could be a bug of node

0 commit comments

Comments
 (0)