Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Try/catch os.userInfo call Fixes #1850
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Aug 15, 2018
1 parent cf093ee commit 6614329
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Binary file modified Go-latest.vsix
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Go",
"version": "0.6.88-beta.1",
"version": "0.6.88-beta.2",
"publisher": "ms-vscode",
"description": "Rich Go language support for Visual Studio Code",
"author": {
Expand Down
5 changes: 2 additions & 3 deletions src/goBuild.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import path = require('path');
import vscode = require('vscode');
import { getToolsEnvVars, runTool, ICheckResult, handleDiagnosticErrors, getWorkspaceFolderPath, getCurrentGoPath } from './util';
import { getToolsEnvVars, runTool, ICheckResult, handleDiagnosticErrors, getWorkspaceFolderPath, getCurrentGoPath, getUserNameHash } from './util';
import { outputChannel } from './goStatus';
import os = require('os');
import { getNonVendorPackages } from './goPackages';
import { getTestFlags } from './testUtils';
import { getStringHash } from './util';
import { getCurrentGoWorkspaceFromGOPATH } from './goPath';
import { diagnosticsStatusBarItem } from './goStatus';
/**
Expand Down Expand Up @@ -71,7 +70,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.' + getStringHash(os.userInfo().username)));
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'];
Expand Down
15 changes: 14 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { NearestNeighborDict, Node } from './avlTree';
const extensionId: string = 'ms-vscode.Go';
const extensionVersion: string = vscode.extensions.getExtension(extensionId).packageJSON.version;
const aiKey: string = 'AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217';
let userNameHash: number = 0;

export const goKeywords: string[] = [
'break',
Expand Down Expand Up @@ -184,7 +185,7 @@ export function canonicalizeGOPATHPrefix(filename: string): string {
*/
export function getStringHash(value: string): number {
let hash = 5381,
i = value.length;
i = value.length;

while (i) {
hash = (hash * 33) ^ value.charCodeAt(--i);
Expand All @@ -196,6 +197,18 @@ export function getStringHash(value: string): number {
return hash >>> 0;
}

export function getUserNameHash() {
if (userNameHash) {
return userNameHash;
}
try {
userNameHash = getStringHash(os.userInfo().username);
} catch (error) {
userNameHash = 1;
}
return userNameHash;
}

/**
* 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
Expand Down

0 comments on commit 6614329

Please sign in to comment.