diff --git a/src/goBuild.ts b/src/goBuild.ts index 4544ec5a5..5222f75fd 100644 --- a/src/goBuild.ts +++ b/src/goBuild.ts @@ -5,6 +5,7 @@ import { outputChannel } from './goStatus'; import os = require('os'); import { getNonVendorPackages } from './goPackages'; import { getTestFlags } from './testUtils'; +import { getUsernameHash } from './util'; import { getCurrentGoWorkspaceFromGOPATH } from './goPath'; import { diagnosticsStatusBarItem } from './goStatus'; /** @@ -56,7 +57,7 @@ export function goBuild(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfigura } const buildEnv = Object.assign({}, getToolsEnvVars()); - const tmpPath = path.normalize(path.join(os.tmpdir(), 'go-code-check')); + const tmpPath = path.normalize(path.join(os.tmpdir(), 'go-code-check.' + getUsernameHash())); const isTestFile = fileUri && fileUri.fsPath.endsWith('_test.go'); const buildFlags: string[] = isTestFile ? getTestFlags(goConfig, null) : (Array.isArray(goConfig['buildFlags']) ? [...goConfig['buildFlags']] : []); const buildArgs: string[] = isTestFile ? ['test', '-c'] : ['build']; diff --git a/src/util.ts b/src/util.ts index a57b9f40a..6d59d7e68 100644 --- a/src/util.ts +++ b/src/util.ts @@ -178,6 +178,25 @@ export function canonicalizeGOPATHPrefix(filename: string): string { return currentWorkspace + filename.slice(currentWorkspace.length); } +/** + * Gets a numeric hash based on the current users username. + * Returns a number between 0 and 4294967295. + */ +export function getUsernameHash(): number { + const user: string = os.userInfo().username; + let hash = 5381, + i = user.length; + + while (i) { + hash = (hash * 33) ^ user.charCodeAt(--i); + } + + /* JavaScript does bitwise operations (like XOR, above) on 32-bit signed + * integers. Since we want the results to be always positive, convert the + * signed int to an unsigned by doing an unsigned bitshift. */ + return hash >>> 0; +} + /** * Gets version of Go based on the output of the command `go version`. * Returns null if go is being used from source/tip in which case `go version` will not return release tag like go1.6.3