mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
windows ipc handles should be scoped to user data dir
This commit is contained in:
parent
91d6637591
commit
243ccb42de
|
@ -15,38 +15,18 @@ import { memoize } from 'vs/base/common/decorators';
|
|||
import pkg from 'vs/platform/node/package';
|
||||
import product from 'vs/platform/node/product';
|
||||
|
||||
function getUniqueUserId(): string {
|
||||
let username: string;
|
||||
if (process.platform === 'win32') {
|
||||
username = process.env.USERNAME;
|
||||
} else {
|
||||
username = process.env.USER;
|
||||
}
|
||||
|
||||
if (!username) {
|
||||
return ''; // fail gracefully if there is no user name
|
||||
}
|
||||
|
||||
// use sha256 to ensure the userid value can be used in filenames and are unique
|
||||
return crypto.createHash('sha256').update(username).digest('hex').substr(0, 6);
|
||||
}
|
||||
|
||||
function getNixIPCHandle(userDataPath: string, type: string): string {
|
||||
return path.join(userDataPath, `${pkg.version}-${type}.sock`);
|
||||
}
|
||||
|
||||
function getWin32IPCHandle(type: string): string {
|
||||
// Support to run VS Code multiple times as different user
|
||||
// by making the socket unique over the logged in user
|
||||
const userId = getUniqueUserId();
|
||||
const name = product.applicationName + (userId ? `-${userId}` : '');
|
||||
|
||||
return `\\\\.\\pipe\\${name}-${pkg.version}-${type}-sock`;
|
||||
function getWin32IPCHandle(userDataPath: string, type: string): string {
|
||||
const scope = crypto.createHash('md5').update(userDataPath).digest('hex');
|
||||
return `\\\\.\\pipe\\${scope}-${pkg.version}-${type}-sock`;
|
||||
}
|
||||
|
||||
function getIPCHandle(userDataPath: string, type: string): string {
|
||||
if (process.platform === 'win32') {
|
||||
return getWin32IPCHandle(type);
|
||||
return getWin32IPCHandle(userDataPath, type);
|
||||
} else {
|
||||
return getNixIPCHandle(userDataPath, type);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue