Skip to content

Commit 02daa28

Browse files
committed
Add the install.lock for each dependency
1 parent 1825782 commit 02daa28

File tree

11 files changed

+71
-45
lines changed

11 files changed

+71
-45
lines changed

src/CSharpExtDownloader.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as util from './common';
76
import { PlatformInformation } from './platform';
8-
import { PackageInstallation, LogPlatformInfo, InstallationSuccess, InstallationFailure } from './omnisharp/loggingEvents';
7+
import { PackageInstallation, LogPlatformInfo, InstallationSuccess } from './omnisharp/loggingEvents';
98
import { EventStream } from './EventStream';
109
import { DownloadAndInstallPackages } from './packageManager/PackageManager';
1110
import { Package } from './packageManager/Package';
@@ -26,30 +25,18 @@ export class CSharpExtDownloader {
2625

2726
public async installRuntimeDependencies(): Promise<boolean> {
2827
this.eventStream.post(new PackageInstallation("C# dependencies"));
29-
let installationStage = 'touchBeginFile';
3028

3129
try {
32-
await util.touchInstallFile(util.InstallFileType.Begin);
3330
// Display platform information and RID
3431
this.eventStream.post(new LogPlatformInfo(this.platformInfo));
3532
let runTimeDependencies = GetRunTimeDependenciesPackages(this.packageJSON);
36-
installationStage = 'downloadAndInstallPackages';
3733
await DownloadAndInstallPackages(runTimeDependencies, this.networkSettingsProvider, this.platformInfo, this.eventStream, this.extensionPath);
38-
installationStage = 'touchLockFile';
39-
await util.touchInstallFile(util.InstallFileType.Lock);
4034
this.eventStream.post(new InstallationSuccess());
4135
return true;
4236
}
4337
catch (error) {
44-
this.eventStream.post(new InstallationFailure(installationStage, error));
4538
return false;
4639
}
47-
finally {
48-
try {
49-
util.deleteInstallFile(util.InstallFileType.Begin);
50-
}
51-
catch (error) { }
52-
}
5340
}
5441
}
5542

src/common.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as cp from 'child_process';
77
import * as fs from 'fs';
88
import * as os from 'os';
99
import * as path from 'path';
10+
import { AbsolutePath } from './packageManager/AbsolutePath';
1011

1112
let extensionPath: string;
1213

@@ -129,18 +130,18 @@ export enum InstallFileType {
129130
Lock
130131
}
131132

132-
function getInstallFilePath(type: InstallFileType): string {
133+
export function getInstallFilePath(folderPath: AbsolutePath, type: InstallFileType): string {
133134
let installFile = 'install.' + InstallFileType[type];
134-
return path.resolve(getExtensionPath(), installFile);
135+
return path.resolve(folderPath.value, installFile);
135136
}
136137

137-
export async function installFileExists(type: InstallFileType): Promise<boolean> {
138-
return fileExists(getInstallFilePath(type));
138+
export async function installFileExists(folderPath: AbsolutePath, type: InstallFileType): Promise<boolean> {
139+
return fileExists(getInstallFilePath(folderPath, type));
139140
}
140141

141-
export async function touchInstallFile(type: InstallFileType): Promise<void> {
142+
export async function touchInstallFile(folderPath: AbsolutePath, type: InstallFileType): Promise<void> {
142143
return new Promise<void>((resolve, reject) => {
143-
fs.writeFile(getInstallFilePath(type), '', err => {
144+
fs.writeFile(getInstallFilePath(folderPath, type), '', err => {
144145
if (err) {
145146
reject(err);
146147
return;
@@ -151,9 +152,9 @@ export async function touchInstallFile(type: InstallFileType): Promise<void> {
151152
});
152153
}
153154

154-
export async function deleteInstallFile(type: InstallFileType): Promise<void> {
155+
export async function deleteInstallFile(folderPath: AbsolutePath, type: InstallFileType): Promise<void> {
155156
return new Promise<void>((resolve, reject) => {
156-
fs.unlink(getInstallFilePath(type), err => {
157+
fs.unlink(getInstallFilePath(folderPath, type), err => {
157158
if (err) {
158159
reject(err);
159160
return;

src/coreclr-debug/activate.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { PlatformInformation } from './../platform';
1111
import { DebuggerPrerequisiteWarning, DebuggerPrerequisiteFailure, DebuggerNotInstalledFailure } from '../omnisharp/loggingEvents';
1212
import { EventStream } from '../EventStream';
1313
import CSharpExtensionExports from '../CSharpExtensionExports';
14+
import { getRuntimeDependencyPackageWithId } from '../tools/GetRuntimeDependencyWithId';
1415

1516
let _debugUtil: CoreClrDebugUtil = null;
1617

@@ -112,7 +113,7 @@ interface AdapterExecutableCommand {
112113
// The default extension manifest calls this command as the adapterExecutableCommand
113114
// If the debugger components have not finished downloading, the proxy displays an error message to the user
114115
// Else it will launch the debug adapter
115-
export async function getAdapterExecutionCommand(platformInfo: PlatformInformation, eventStream: EventStream): Promise<AdapterExecutableCommand> {
116+
export async function getAdapterExecutionCommand(platformInfo: PlatformInformation, eventStream: EventStream, packageJSON: any, extensionPath: string): Promise<AdapterExecutableCommand> {
116117
let util = new CoreClrDebugUtil(common.getExtensionPath());
117118

118119
// Check for .debugger folder. Handle if it does not exist.
@@ -125,7 +126,14 @@ export async function getAdapterExecutionCommand(platformInfo: PlatformInformati
125126
// 4. install.complete is created
126127

127128
// install.Lock does not exist, need to wait for packages to finish downloading.
128-
let installLock: boolean = await common.installFileExists(common.InstallFileType.Lock);
129+
let installLock = false;
130+
let debuggerPackage = getRuntimeDependencyPackageWithId("Debugger", packageJSON, platformInfo, extensionPath);
131+
if (debuggerPackage && debuggerPackage.installPath)
132+
{
133+
installLock = await common.installFileExists(debuggerPackage.installPath, common.InstallFileType.Lock);
134+
}
135+
136+
//todo: check if the debugger install.lock is present
129137
if (!installLock) {
130138
eventStream.post(new DebuggerNotInstalledFailure());
131139
throw new Error('The C# extension is still downloading packages. Please see progress in the output window below.');

src/features/commands.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import reportIssue from './reportIssue';
2323
import { IMonoResolver } from '../constants/IMonoResolver';
2424
import { getDotnetInfo } from '../utils/getDotnetInfo';
2525

26-
export default function registerCommands(server: OmniSharpServer, platformInfo: PlatformInformation, eventStream: EventStream, optionProvider: OptionProvider, monoResolver: IMonoResolver): CompositeDisposable {
26+
export default function registerCommands(server: OmniSharpServer, platformInfo: PlatformInformation, eventStream: EventStream, optionProvider: OptionProvider, monoResolver: IMonoResolver, packageJSON: any, extensionPath: string): CompositeDisposable {
2727
let disposable = new CompositeDisposable();
2828
disposable.add(vscode.commands.registerCommand('o.restart', () => restartOmniSharp(server)));
2929
disposable.add(vscode.commands.registerCommand('o.pickProjectAndStart', async () => pickProjectAndStart(server, optionProvider)));
@@ -47,8 +47,8 @@ export default function registerCommands(server: OmniSharpServer, platformInfo:
4747
disposable.add(vscode.commands.registerCommand('csharp.listRemoteProcess', async (args) => RemoteAttachPicker.ShowAttachEntries(args, platformInfo)));
4848

4949
// Register command for adapter executable command.
50-
disposable.add(vscode.commands.registerCommand('csharp.coreclrAdapterExecutableCommand', async (args) => getAdapterExecutionCommand(platformInfo, eventStream)));
51-
disposable.add(vscode.commands.registerCommand('csharp.clrAdapterExecutableCommand', async (args) => getAdapterExecutionCommand(platformInfo, eventStream)));
50+
disposable.add(vscode.commands.registerCommand('csharp.coreclrAdapterExecutableCommand', async (args) => getAdapterExecutionCommand(platformInfo, eventStream, packageJSON, extensionPath)));
51+
disposable.add(vscode.commands.registerCommand('csharp.clrAdapterExecutableCommand', async (args) => getAdapterExecutionCommand(platformInfo, eventStream, packageJSON, extensionPath)));
5252
disposable.add(vscode.commands.registerCommand('csharp.reportIssue', async () => reportIssue(vscode, eventStream, getDotnetInfo, platformInfo.isValidPlatformForMono(), optionProvider.GetLatestOptions(), monoResolver)));
5353

5454
return new CompositeDisposable(disposable);

src/main.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
159159
}
160160

161161
async function ensureRuntimeDependencies(extension: vscode.Extension<CSharpExtensionExports>, eventStream: EventStream, platformInfo: PlatformInformation, networkSettingsProvider: NetworkSettingsProvider): Promise<boolean> {
162-
return util.installFileExists(util.InstallFileType.Lock)
163-
.then(exists => {
164-
if (!exists) {
165-
const downloader = new CSharpExtDownloader(networkSettingsProvider, eventStream, extension.packageJSON, platformInfo, extension.extensionPath);
166-
return downloader.installRuntimeDependencies();
167-
} else {
168-
return true;
169-
}
170-
});
162+
const downloader = new CSharpExtDownloader(networkSettingsProvider, eventStream, extension.packageJSON, platformInfo, extension.extensionPath);
163+
return downloader.installRuntimeDependencies();
171164
}
172165

src/omnisharp/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export async function activate(context: vscode.ExtensionContext, packageJSON: an
9898
localDisposables = null;
9999
}));
100100

101-
disposables.add(registerCommands(server, platformInfo, eventStream, optionProvider, omnisharpMonoResolver));
101+
disposables.add(registerCommands(server, platformInfo, eventStream, optionProvider, omnisharpMonoResolver, packageJSON, extensionPath));
102102

103103
if (!context.workspaceState.get<boolean>('assetPromptDisabled')) {
104104
disposables.add(server.onServerStart(() => {

src/packageManager/AbsolutePathPackage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import { IPackage } from "./IPackage";
88
import { AbsolutePath } from "./AbsolutePath";
99

1010
export class AbsolutePathPackage implements IPackage{
11-
constructor(public description: string,
11+
12+
constructor(public Id: string,
13+
public description: string,
1214
public url: string,
1315
public platforms: string[],
1416
public architectures: string[],
@@ -21,6 +23,7 @@ export class AbsolutePathPackage implements IPackage{
2123

2224
public static getAbsolutePathPackage(pkg: Package, extensionPath: string) {
2325
return new AbsolutePathPackage(
26+
pkg.Id,
2427
pkg.description,
2528
pkg.url,
2629
pkg.platforms,

src/packageManager/IPackage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
export interface IPackage {
7+
Id: string;
78
description: string;
89
url: string;
910
fallbackUrl?: string;

src/packageManager/PackageFilterer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function filterPackages(packages: AbsolutePathPackage[], platformIn
1515
return filterAlreadyInstalledPackages(platformPackages);
1616
}
1717

18-
function filterPlatformPackages(packages: AbsolutePathPackage[], platformInfo: PlatformInformation) {
18+
export function filterPlatformPackages(packages: AbsolutePathPackage[], platformInfo: PlatformInformation) {
1919
if (packages) {
2020
return packages.filter(pkg => {
2121
if (pkg.architectures && pkg.architectures.indexOf(platformInfo.architecture) === -1) {
@@ -36,13 +36,13 @@ function filterPlatformPackages(packages: AbsolutePathPackage[], platformInfo: P
3636

3737
async function filterAlreadyInstalledPackages(packages: AbsolutePathPackage[]): Promise<AbsolutePathPackage[]> {
3838
return filterAsync(packages, async (pkg: AbsolutePathPackage) => {
39-
//If the file is present at the install test path then filter it
40-
let testPath = pkg.installTestPath;
39+
//If the install.Lock file is present for this package then do not install it again
40+
let testPath = util.getInstallFilePath(pkg.installPath, util.InstallFileType.Lock);
4141
if (!testPath) {
42-
//if there is no testPath specified then we will not filter it
42+
//if there is no testPath then we will not filter it
4343
return true;
4444
}
4545

46-
return !(await util.fileExists(testPath.value));
46+
return !(await util.fileExists(testPath));
4747
});
4848
}

src/packageManager/PackageManager.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,41 @@ import { EventStream } from '../EventStream';
1313
import { NetworkSettingsProvider } from "../NetworkSettings";
1414
import { filterPackages } from "./PackageFilterer";
1515
import { AbsolutePathPackage } from "./AbsolutePathPackage";
16+
import { touchInstallFile, InstallFileType, deleteInstallFile } from "../common";
17+
import { InstallationFailure } from "../omnisharp/loggingEvents";
18+
import { mkdirpSync } from "fs-extra";
1619

17-
export async function DownloadAndInstallPackages(packages: Package[], provider: NetworkSettingsProvider, platformInfo: PlatformInformation, eventStream: EventStream, extensionPath: string) {
20+
export async function DownloadAndInstallPackages(packages: Package[], provider: NetworkSettingsProvider, platformInfo: PlatformInformation, eventStream: EventStream, extensionPath: string): Promise<void> {
1821
let absolutePathPackages = packages.map(pkg => AbsolutePathPackage.getAbsolutePathPackage(pkg, extensionPath));
1922
let filteredPackages = await filterPackages(absolutePathPackages, platformInfo);
23+
2024
if (filteredPackages) {
2125
for (let pkg of filteredPackages) {
26+
let installationStage = "touchBeginFile";
2227
try {
28+
mkdirpSync(pkg.installPath.value);
29+
await touchInstallFile(pkg.installPath, InstallFileType.Begin);
30+
installationStage = 'downloadAndInstallPackages';
2331
let buffer = await DownloadFile(pkg.description, eventStream, provider, pkg.url, pkg.fallbackUrl);
2432
await InstallZip(buffer, pkg.description, pkg.installPath, pkg.binaries, eventStream);
33+
installationStage = 'touchLockFile';
34+
await touchInstallFile(pkg.installPath, InstallFileType.Lock);
2535
}
2636
catch (error) {
37+
eventStream.post(new InstallationFailure(installationStage, error));
2738
if (error instanceof NestedError) {
28-
throw new PackageError(error.message, pkg, error.err);
39+
let packageError = new PackageError(error.message, pkg, error.err);
40+
eventStream.post(new InstallationFailure(installationStage, packageError));
41+
throw packageError;
2942
}
3043
else {
44+
eventStream.post(new InstallationFailure(installationStage, error));
3145
throw error;
3246
}
3347
}
48+
finally {
49+
await deleteInstallFile(pkg.installPath, InstallFileType.Begin);
50+
}
3451
}
3552
}
3653
}

0 commit comments

Comments
 (0)