923
924
export function createStaticIPCHandle(directoryPath: string, type: string, version: string): string {
925
>
const scope = createHash('sha256').update(directoryPath).digest('hex');
ipc.net.ts
926
>
const scopeForSocket = scope.substr(0, 8);
927
>
928
>
// Windows: use named pipe
929
>
if (process.platform === 'win32') {
930
return `\\\\.\\pipe\\${scopeForSocket}-${version}-${type}-sock`;
931
}
933
>
// Mac & Unix: Use socket file
934
>
// Unix: Prefer XDG_RUNTIME_DIR over user data path, unless portable
935
>
// Trim the version and type values for the socket to prevent too large
936
>
// file names causing issues: https://unix.stackexchange.com/q/367008
937
>
938
>
const versionForSocket = version.substr(0, 4);
939
>
const typeForSocket = type.substr(0, 6);
940
>
941
>
let result: string;
942
>
if (process.platform !== 'darwin' && XDG_RUNTIME_DIR && !process.env['VSCODE_PORTABLE']) {
943
result = join(XDG_RUNTIME_DIR, `vscode-${scopeForSocket}-${versionForSocket}-${typeForSocket}.sock`);
945
>
result = join(directoryPath, `${versionForSocket}-${typeForSocket}.sock`);
946
>
}
947
>
948
>
// Validate length. Unlike `createRandomIPCHandle`, the path here must be derived
949
>
// deterministically from `directoryPath` so that the server and its clients agree
950
>
// on the same socket. There is no random component to trim, so an over-long
951
>
// `--user-data-dir` can still produce a path that exceeds the platform limit.
952
>
validateIPCHandleLength(result);
953
>
954
>
return result;
955
>
}
956
957
>
function validateIPCHandleLength(handle: string): void {
ipc.net.ts
958
>
const limit = safeIpcPathLengths[platform];
959
>
if (typeof limit === 'number' && handle.length >= limit) {
960
// https://nodejs.org/api/net.html#net_identifying_paths_for_ipc_connections
961
console.warn(`WARNING: IPC handle "${handle}" is longer than ${limit} chars, try a shorter --user-data-dir`);
962
}
964
965
export class Server extends IPCServer {