Skip to content

Commit

Permalink
main: add a lockfile, and set the user data dir while debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Jul 9, 2021
1 parent 9044b2c commit 126218b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ test-results/
yarn-error.log
vscode.lsif
vscode.db
/.profile-oss
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
"cascadeTerminateToConfigurations": [
"Attach to Extension Host"
],
"userDataDir": false,
"userDataDir": "${workspaceFolder}/.profile-oss",
"pauseForSourceMap": false,
"outFiles": [
"${workspaceFolder}/out/**/*.js"
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files.exclude": {
".git": true,
".build": true,
".profile-oss": true,
"**/.DS_Store": true,
"build/**/*.js": {
"when": "$(basename).ts"
Expand Down
16 changes: 16 additions & 0 deletions src/vs/code/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { cwd } from 'vs/base/common/process';
import { IProtocolMainService } from 'vs/platform/protocol/electron-main/protocol';
import { ProtocolMainService } from 'vs/platform/protocol/electron-main/protocolMainService';
import { Promises } from 'vs/base/common/async';
import { toDisposable } from 'vs/base/common/lifecycle';

/**
* The main VS Code entry point.
Expand Down Expand Up @@ -339,6 +340,9 @@ class CodeMain {
throw new ExpectedError('Sent env to running instance. Terminating...');
}

const lockFile = await this.createLockfile(environmentMainService);
once(lifecycleMainService.onWillShutdown)(() => lockFile.dispose());

// Print --status usage info
if (environmentMainService.args.status) {
logService.warn('Warning: The --status argument can only be used if Code is already running. Please run it again after Code has started.');
Expand Down Expand Up @@ -419,6 +423,18 @@ class CodeMain {
lifecycleMainService.kill(exitCode);
}

private async createLockfile(env: IEnvironmentMainService) {
await FSPromises.writeFile(env.mainLockfile, String(process.pid));

return toDisposable(() => {
try {
unlinkSync(env.mainLockfile);
} catch {
// ignored
}
});
}

//#region Command line arguments utilities

private resolveArgs(): NativeParsedArgs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface IEnvironmentMainService extends INativeEnvironmentService {

// --- IPC
mainIPCHandle: string;
mainLockfile: string;

// --- config
sandbox: boolean;
Expand All @@ -52,6 +53,9 @@ export class EnvironmentMainService extends NativeEnvironmentService implements
@memoize
get mainIPCHandle(): string { return createStaticIPCHandle(this.userDataPath, 'main', this.productService.version); }

@memoize
get mainLockfile(): string { return join(this.userDataPath, 'code.lock'); }

@memoize
get sandbox(): boolean { return !!this.args['__sandbox']; }

Expand Down

0 comments on commit 126218b

Please sign in to comment.