mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-05 09:35:39 -05:00
Merge from vscode fcf3346a8e9f5ee1e00674461d9e2c2292a14ee3 (#12295)
* Merge from vscode fcf3346a8e9f5ee1e00674461d9e2c2292a14ee3 * Fix test build break * Update distro * Fix build errors * Update distro * Update REH build file * Update build task names for REL * Fix product build yaml * Fix product REH task name * Fix type in task name * Update linux build step * Update windows build tasks * Turn off server publish * Disable REH * Fix typo * Bump distro * Update vscode tests * Bump distro * Fix type in disto * Bump distro * Turn off docker build * Remove docker step from release Co-authored-by: ADS Merger <andresse@microsoft.com> Co-authored-by: Karl Burtram <karlb@microsoft.com>
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
import * as nls from 'vs/nls';
|
||||
import * as path from 'vs/base/common/path';
|
||||
import * as pfs from 'vs/base/node/pfs';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { toDisposable, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { zip, IFile } from 'vs/base/node/zip';
|
||||
import {
|
||||
@@ -22,8 +21,7 @@ import {
|
||||
ExtensionManagementError
|
||||
} from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { areSameExtensions, getGalleryExtensionId, getMaliciousExtensionsSet, getGalleryExtensionTelemetryData, getLocalExtensionTelemetryData, ExtensionIdentifierWithVersion } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
|
||||
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { createCancelablePromise, CancelablePromise } from 'vs/base/common/async';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import * as semver from 'semver-umd';
|
||||
@@ -66,7 +64,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
private readonly extensionsScanner: ExtensionsScanner;
|
||||
private reportedExtensions: Promise<IReportedExtension[]> | undefined;
|
||||
private lastReportTimestamp = 0;
|
||||
private readonly installingExtensions: Map<string, CancelablePromise<ILocalExtension>> = new Map<string, CancelablePromise<ILocalExtension>>();
|
||||
private readonly installingExtensions = new Map<string, CancelablePromise<ILocalExtension>>();
|
||||
private readonly uninstallingExtensions: Map<string, CancelablePromise<void>> = new Map<string, CancelablePromise<void>>();
|
||||
private readonly manifestCache: ExtensionsManifestCache;
|
||||
private readonly extensionsDownloader: ExtensionsDownloader;
|
||||
@@ -105,16 +103,17 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
}));
|
||||
}
|
||||
|
||||
zip(extension: ILocalExtension): Promise<URI> {
|
||||
async zip(extension: ILocalExtension): Promise<URI> {
|
||||
this.logService.trace('ExtensionManagementService#zip', extension.identifier.id);
|
||||
return this.collectFiles(extension)
|
||||
.then(files => zip(path.join(tmpdir(), generateUuid()), files))
|
||||
.then<URI>(path => URI.file(path));
|
||||
const files = await this.collectFiles(extension);
|
||||
const location = await zip(path.join(tmpdir(), generateUuid()), files);
|
||||
return URI.file(location);
|
||||
}
|
||||
|
||||
unzip(zipLocation: URI): Promise<IExtensionIdentifier> {
|
||||
async unzip(zipLocation: URI): Promise<IExtensionIdentifier> {
|
||||
this.logService.trace('ExtensionManagementService#unzip', zipLocation.toString());
|
||||
return this.install(zipLocation).then(local => local.identifier);
|
||||
const local = await this.install(zipLocation);
|
||||
return local.identifier;
|
||||
}
|
||||
|
||||
async getManifest(vsix: URI): Promise<IExtensionManifest> {
|
||||
@@ -123,7 +122,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
return getManifest(zipPath);
|
||||
}
|
||||
|
||||
private collectFiles(extension: ILocalExtension): Promise<IFile[]> {
|
||||
private async collectFiles(extension: ILocalExtension): Promise<IFile[]> {
|
||||
|
||||
const collectFilesFromDirectory = async (dir: string): Promise<string[]> => {
|
||||
let entries = await pfs.readdir(dir);
|
||||
@@ -144,113 +143,119 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
return promise;
|
||||
};
|
||||
|
||||
return collectFilesFromDirectory(extension.location.fsPath)
|
||||
.then(files => files.map(f => (<IFile>{ path: `extension/${path.relative(extension.location.fsPath, f)}`, localPath: f })));
|
||||
|
||||
const files = await collectFilesFromDirectory(extension.location.fsPath);
|
||||
return files.map(f => (<IFile>{ path: `extension/${path.relative(extension.location.fsPath, f)}`, localPath: f }));
|
||||
}
|
||||
|
||||
install(vsix: URI, isMachineScoped?: boolean): Promise<ILocalExtension> {
|
||||
async install(vsix: URI, isMachineScoped?: boolean): Promise<ILocalExtension> {
|
||||
// {{SQL CARBON EDIT}}
|
||||
let startTime = new Date().getTime();
|
||||
|
||||
this.logService.trace('ExtensionManagementService#install', vsix.toString());
|
||||
return createCancelablePromise(token => {
|
||||
return this.downloadVsix(vsix).then(downloadLocation => {
|
||||
const zipPath = path.resolve(downloadLocation.fsPath);
|
||||
return createCancelablePromise(async token => {
|
||||
|
||||
return getManifest(zipPath)
|
||||
.then(manifest => {
|
||||
const identifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
|
||||
// let operation: InstallOperation = InstallOperation.Install; {{SQL CARBON EDIT}} comment out for no unused
|
||||
// {{SQL CARBON EDIT - Check VSCode and ADS version}}
|
||||
if (manifest.engines && ((manifest.engines.vscode && !isEngineValid(manifest.engines.vscode, product.vscodeVersion)) || (manifest.engines.azdata && !isEngineValid(manifest.engines.azdata, product.version)))) {
|
||||
return Promise.reject(new Error(nls.localize('incompatible', "Unable to install extension '{0}' as it is not compatible with Azure Data Studio '{1}'.", identifier.id, product.version)));
|
||||
}
|
||||
const identifierWithVersion = new ExtensionIdentifierWithVersion(identifier, manifest.version);
|
||||
return this.getInstalled(ExtensionType.User)
|
||||
.then(installedExtensions => {
|
||||
const existing = installedExtensions.filter(i => areSameExtensions(identifier, i.identifier))[0];
|
||||
if (existing) {
|
||||
isMachineScoped = isMachineScoped || existing.isMachineScoped;
|
||||
// operation = InstallOperation.Update;
|
||||
if (identifierWithVersion.equals(new ExtensionIdentifierWithVersion(existing.identifier, existing.manifest.version))) {
|
||||
return this.extensionsScanner.removeExtension(existing, 'existing').then(null, e => Promise.reject(new Error(nls.localize('restartCode', "Please restart Azure Data Studio before reinstalling {0}.", manifest.displayName || manifest.name))));
|
||||
} else if (semver.gt(existing.manifest.version, manifest.version)) {
|
||||
return this.uninstallExtension(existing);
|
||||
}
|
||||
} else {
|
||||
// Remove the extension with same version if it is already uninstalled.
|
||||
// Installing a VSIX extension shall replace the existing extension always.
|
||||
return this.unsetUninstalledAndGetLocal(identifierWithVersion)
|
||||
.then(existing => {
|
||||
if (existing) {
|
||||
return this.extensionsScanner.removeExtension(existing, 'existing').then(null, e => Promise.reject(new Error(nls.localize('restartCode', "Please restart Azure Data Studio before reinstalling {0}.", manifest.displayName || manifest.name))));
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
return undefined;
|
||||
})
|
||||
.then(() => {
|
||||
this.logService.info('Installing the extension:', identifier.id);
|
||||
this._onInstallExtension.fire({ identifier, zipPath });
|
||||
// {{SQL CARBON EDIT}}
|
||||
// Until there's a gallery for SQL Ops Studio, skip retrieving the metadata from the gallery
|
||||
return this.installExtension({ zipPath, identifierWithVersion, metadata: { isMachineScoped } }, token)
|
||||
.then(
|
||||
local => {
|
||||
this.reportTelemetry(this.getTelemetryEvent(InstallOperation.Install), getLocalExtensionTelemetryData(local), new Date().getTime() - startTime, void 0);
|
||||
this._onDidInstallExtension.fire({ identifier, zipPath, local, operation: InstallOperation.Install });
|
||||
return local;
|
||||
},
|
||||
error => { this._onDidInstallExtension.fire({ identifier, zipPath, error, operation: InstallOperation.Install }); return Promise.reject(error); }
|
||||
);
|
||||
// return this.getMetadata(getGalleryExtensionId(manifest.publisher, manifest.name))
|
||||
// .then(
|
||||
// metadata => this.installFromZipPath(identifierWithVersion, zipPath, metadata, type, operation, token),
|
||||
// () => this.installFromZipPath(identifierWithVersion, zipPath, null, type, operation, token))
|
||||
// .then(
|
||||
// local => { this.logService.info('Successfully installed the extension:', identifier.id); return local; },
|
||||
// e => {
|
||||
// this.logService.error('Failed to install the extension:', identifier.id, e.message);
|
||||
// return Promise.reject(e);
|
||||
// });
|
||||
// {{SQL CARBON EDIT}} - End
|
||||
});
|
||||
});
|
||||
});
|
||||
const downloadLocation = await this.downloadVsix(vsix);
|
||||
const zipPath = path.resolve(downloadLocation.fsPath);
|
||||
|
||||
const manifest = await getManifest(zipPath);
|
||||
const identifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
|
||||
// let operation: InstallOperation = InstallOperation.Install; {{ SQL CARBON EDIT }}
|
||||
// {{ SQL CARBON EDIT }}
|
||||
if (manifest.engines && ((manifest.engines.vscode && !isEngineValid(manifest.engines.vscode, product.vscodeVersion)) || (manifest.engines.azdata && !isEngineValid(manifest.engines.azdata, product.version)))) {
|
||||
throw new Error(nls.localize('incompatible', "Unable to install extension '{0}' as it is not compatible with VS Code '{1}'.", identifier.id, product.version));
|
||||
}
|
||||
|
||||
const identifierWithVersion = new ExtensionIdentifierWithVersion(identifier, manifest.version);
|
||||
const installedExtensions = await this.getInstalled(ExtensionType.User);
|
||||
const existing = installedExtensions.find(i => areSameExtensions(identifier, i.identifier));
|
||||
if (existing) {
|
||||
isMachineScoped = isMachineScoped || existing.isMachineScoped;
|
||||
// operation = InstallOperation.Update; {{ SQL CARBON EDIT }}
|
||||
if (identifierWithVersion.equals(new ExtensionIdentifierWithVersion(existing.identifier, existing.manifest.version))) {
|
||||
try {
|
||||
await this.extensionsScanner.removeExtension(existing, 'existing');
|
||||
} catch (e) {
|
||||
throw new Error(nls.localize('restartCode', "Please restart VS Code before reinstalling {0}.", manifest.displayName || manifest.name));
|
||||
}
|
||||
} else if (semver.gt(existing.manifest.version, manifest.version)) {
|
||||
await this.uninstallExtension(existing);
|
||||
}
|
||||
} else {
|
||||
// Remove the extension with same version if it is already uninstalled.
|
||||
// Installing a VSIX extension shall replace the existing extension always.
|
||||
const existing = await this.unsetUninstalledAndGetLocal(identifierWithVersion);
|
||||
if (existing) {
|
||||
try {
|
||||
await this.extensionsScanner.removeExtension(existing, 'existing');
|
||||
} catch (e) {
|
||||
throw new Error(nls.localize('restartCode', "Please restart VS Code before reinstalling {0}.", manifest.displayName || manifest.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.logService.info('Installing the extension:', identifier.id);
|
||||
this._onInstallExtension.fire({ identifier, zipPath });
|
||||
|
||||
// {{SQL CARBON EDIT}}
|
||||
// Until there's a gallery for SQL Ops Studio, skip retrieving the metadata from the gallery
|
||||
return this.installExtension({ zipPath, identifierWithVersion, metadata: { isMachineScoped } }, token)
|
||||
.then(
|
||||
local => {
|
||||
this.reportTelemetry(this.getTelemetryEvent(InstallOperation.Install), getLocalExtensionTelemetryData(local), new Date().getTime() - startTime, void 0);
|
||||
this._onDidInstallExtension.fire({ identifier, zipPath, local, operation: InstallOperation.Install });
|
||||
return local;
|
||||
},
|
||||
error => { this._onDidInstallExtension.fire({ identifier, zipPath, error, operation: InstallOperation.Install }); return Promise.reject(error); }
|
||||
);
|
||||
// {{ SQL CARBON EDIT }}
|
||||
// let metadata: IGalleryMetadata | undefined;
|
||||
// try {
|
||||
// metadata = await this.getGalleryMetadata(getGalleryExtensionId(manifest.publisher, manifest.name));
|
||||
// } catch (e) { /* Ignore */ }
|
||||
// try {
|
||||
// const local = await this.installFromZipPath(identifierWithVersion, zipPath, isMachineScoped ? { ...(metadata || {}), isMachineScoped } : metadata, operation, token);
|
||||
// this.logService.info('Successfully installed the extension:', identifier.id);
|
||||
// return local;
|
||||
// } catch (e) {
|
||||
// this.logService.error('Failed to install the extension:', identifier.id, e.message);
|
||||
// throw e;
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
private downloadVsix(vsix: URI): Promise<URI> {
|
||||
private async downloadVsix(vsix: URI): Promise<URI> {
|
||||
if (vsix.scheme === Schemas.file) {
|
||||
return Promise.resolve(vsix);
|
||||
return vsix;
|
||||
}
|
||||
if (!this.downloadService) {
|
||||
throw new Error('Download service is not available');
|
||||
}
|
||||
const downloadedLocation = path.join(tmpdir(), generateUuid());
|
||||
return this.downloadService.download(vsix, URI.file(downloadedLocation)).then(() => URI.file(downloadedLocation));
|
||||
|
||||
const downloadedLocation = URI.file(path.join(tmpdir(), generateUuid()));
|
||||
await this.downloadService.download(vsix, downloadedLocation);
|
||||
return downloadedLocation;
|
||||
}
|
||||
|
||||
/*private installFromZipPath(identifierWithVersion: ExtensionIdentifierWithVersion, zipPath: string, metadata: IMetadata | undefined, operation: InstallOperation, token: CancellationToken): Promise<ILocalExtension> { {{SQL CARBON EDIT}}
|
||||
return this.toNonCancellablePromise(this.installExtension({ zipPath, identifierWithVersion, metadata }, token)
|
||||
.then(local => this.installDependenciesAndPackExtensions(local, undefined)
|
||||
.then(
|
||||
() => local,
|
||||
error => {
|
||||
if (isNonEmptyArray(local.manifest.extensionDependencies)) {
|
||||
this.logService.warn(`Cannot install dependencies of extension:`, local.identifier.id, error.message);
|
||||
}
|
||||
if (isNonEmptyArray(local.manifest.extensionPack)) {
|
||||
this.logService.warn(`Cannot install packed extensions of extension:`, local.identifier.id, error.message);
|
||||
}
|
||||
return local;
|
||||
}))
|
||||
.then(
|
||||
local => { this._onDidInstallExtension.fire({ identifier: identifierWithVersion.identifier, zipPath, local, operation }); return local; },
|
||||
error => { this._onDidInstallExtension.fire({ identifier: identifierWithVersion.identifier, zipPath, operation, error }); return Promise.reject(error); }
|
||||
));
|
||||
// {{ SQL CARBON EDIT }}
|
||||
/*private async installFromZipPath(identifierWithVersion: ExtensionIdentifierWithVersion, zipPath: string, metadata: IMetadata | undefined, operation: InstallOperation, token: CancellationToken): Promise<ILocalExtension> {
|
||||
try {
|
||||
const local = await this.installExtension({ zipPath, identifierWithVersion, metadata }, token);
|
||||
try {
|
||||
await this.installDependenciesAndPackExtensions(local, undefined);
|
||||
} catch (error) {
|
||||
if (isNonEmptyArray(local.manifest.extensionDependencies)) {
|
||||
this.logService.warn(`Cannot install dependencies of extension:`, local.identifier.id, error.message);
|
||||
}
|
||||
if (isNonEmptyArray(local.manifest.extensionPack)) {
|
||||
this.logService.warn(`Cannot install packed extensions of extension:`, local.identifier.id, error.message);
|
||||
}
|
||||
}
|
||||
this._onDidInstallExtension.fire({ identifier: identifierWithVersion.identifier, zipPath, local, operation });
|
||||
return local;
|
||||
} catch (error) {
|
||||
this._onDidInstallExtension.fire({ identifier: identifierWithVersion.identifier, zipPath, operation, error });
|
||||
throw error;
|
||||
}
|
||||
}*/
|
||||
|
||||
async canInstall(extension: IGalleryExtension): Promise<boolean> {
|
||||
@@ -259,17 +264,68 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
|
||||
async installFromGallery(extension: IGalleryExtension, isMachineScoped?: boolean): Promise<ILocalExtension> {
|
||||
if (!this.galleryService.isEnabled()) {
|
||||
return Promise.reject(new Error(nls.localize('MarketPlaceDisabled', "Marketplace is not enabled")));
|
||||
throw new Error(nls.localize('MarketPlaceDisabled', "Marketplace is not enabled"));
|
||||
}
|
||||
const startTime = new Date().getTime();
|
||||
|
||||
const onDidInstallExtensionSuccess = (extension: IGalleryExtension, operation: InstallOperation, local: ILocalExtension) => {
|
||||
try {
|
||||
extension = await this.checkAndGetCompatibleVersion(extension);
|
||||
} catch (error) {
|
||||
const errorCode = error && (<ExtensionManagementError>error).code ? (<ExtensionManagementError>error).code : ERROR_UNKNOWN;
|
||||
this.logService.error(`Failed to install extension:`, extension.identifier.id, error ? error.message : errorCode);
|
||||
this.reportTelemetry(this.getTelemetryEvent(InstallOperation.Install), getGalleryExtensionTelemetryData(extension), undefined, error);
|
||||
if (error instanceof Error) {
|
||||
error.name = errorCode;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
const key = new ExtensionIdentifierWithVersion(extension.identifier, extension.version).key();
|
||||
let cancellablePromise = this.installingExtensions.get(key);
|
||||
if (!cancellablePromise) {
|
||||
cancellablePromise = createCancelablePromise(token => this.doInstallFromGallery(extension, !!isMachineScoped, token));
|
||||
this.installingExtensions.set(key, cancellablePromise);
|
||||
cancellablePromise.finally(() => this.installingExtensions.delete(key));
|
||||
}
|
||||
|
||||
return cancellablePromise;
|
||||
}
|
||||
|
||||
private async doInstallFromGallery(extension: IGalleryExtension, isMachineScoped: boolean, token: CancellationToken): Promise<ILocalExtension> {
|
||||
const startTime = new Date().getTime();
|
||||
let operation: InstallOperation = InstallOperation.Install;
|
||||
this.logService.info('Installing extension:', extension.identifier.id);
|
||||
this._onInstallExtension.fire({ identifier: extension.identifier, gallery: extension });
|
||||
|
||||
try {
|
||||
const installed = await this.getInstalled(ExtensionType.User);
|
||||
const existingExtension = installed.find(i => areSameExtensions(i.identifier, extension.identifier));
|
||||
if (existingExtension) {
|
||||
operation = InstallOperation.Update;
|
||||
}
|
||||
|
||||
const installableExtension = await this.downloadInstallableExtension(extension, operation);
|
||||
installableExtension.metadata.isMachineScoped = isMachineScoped || existingExtension?.isMachineScoped;
|
||||
const local = await this.installExtension(installableExtension, token);
|
||||
|
||||
try { await this.extensionsDownloader.delete(URI.file(installableExtension.zipPath)); } catch (error) { /* Ignore */ }
|
||||
|
||||
try {
|
||||
await this.installDependenciesAndPackExtensions(local, existingExtension);
|
||||
} catch (error) {
|
||||
try { await this.uninstall(local); } catch (error) { /* Ignore */ }
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (existingExtension && semver.neq(existingExtension.manifest.version, extension.version)) {
|
||||
await this.setUninstalled(existingExtension);
|
||||
}
|
||||
|
||||
this.logService.info(`Extensions installed successfully:`, extension.identifier.id);
|
||||
this._onDidInstallExtension.fire({ identifier: extension.identifier, gallery: extension, local, operation });
|
||||
this.reportTelemetry(this.getTelemetryEvent(operation), getGalleryExtensionTelemetryData(extension), new Date().getTime() - startTime, undefined);
|
||||
};
|
||||
return local;
|
||||
|
||||
const onDidInstallExtensionFailure = (extension: IGalleryExtension, operation: InstallOperation, error: Error) => {
|
||||
} catch (error) {
|
||||
const errorCode = error && (<ExtensionManagementError>error).code ? (<ExtensionManagementError>error).code : ERROR_UNKNOWN;
|
||||
this.logService.error(`Failed to install extension:`, extension.identifier.id, error ? error.message : errorCode);
|
||||
this._onDidInstallExtension.fire({ identifier: extension.identifier, gallery: extension, operation, error: errorCode });
|
||||
@@ -277,162 +333,107 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
if (error instanceof Error) {
|
||||
error.name = errorCode;
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
extension = await this.checkAndGetCompatibleVersion(extension);
|
||||
} catch (error) {
|
||||
onDidInstallExtensionFailure(extension, InstallOperation.Install, error);
|
||||
return Promise.reject(error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
const key = new ExtensionIdentifierWithVersion(extension.identifier, extension.version).key();
|
||||
let cancellablePromise = this.installingExtensions.get(key);
|
||||
if (!cancellablePromise) {
|
||||
|
||||
this.logService.info('Installing extension:', extension.identifier.id);
|
||||
this._onInstallExtension.fire({ identifier: extension.identifier, gallery: extension });
|
||||
|
||||
let operation: InstallOperation = InstallOperation.Install;
|
||||
let cancellationToken: CancellationToken, successCallback: (local: ILocalExtension) => void, errorCallback: (e?: any) => any | null;
|
||||
cancellablePromise = createCancelablePromise(token => { cancellationToken = token; return new Promise((c, e) => { successCallback = c; errorCallback = e; }); });
|
||||
this.installingExtensions.set(key, cancellablePromise);
|
||||
try {
|
||||
const installed = await this.getInstalled(ExtensionType.User);
|
||||
const existingExtension = installed.find(i => areSameExtensions(i.identifier, extension.identifier));
|
||||
if (existingExtension) {
|
||||
operation = InstallOperation.Update;
|
||||
}
|
||||
|
||||
this.downloadInstallableExtension(extension, operation)
|
||||
.then(installableExtension => {
|
||||
installableExtension.metadata.isMachineScoped = isMachineScoped || existingExtension?.isMachineScoped;
|
||||
return this.installExtension(installableExtension, cancellationToken)
|
||||
.then(local => this.extensionsDownloader.delete(URI.file(installableExtension.zipPath)).finally(() => { }).then(() => local));
|
||||
})
|
||||
.then(local => this.installDependenciesAndPackExtensions(local, existingExtension)
|
||||
.then(() => local, error => this.uninstall(local).then(() => Promise.reject(error), () => Promise.reject(error))))
|
||||
.then(
|
||||
async local => {
|
||||
if (existingExtension && semver.neq(existingExtension.manifest.version, extension.version)) {
|
||||
await this.setUninstalled(existingExtension);
|
||||
}
|
||||
this.installingExtensions.delete(key);
|
||||
onDidInstallExtensionSuccess(extension, operation, local);
|
||||
successCallback(local);
|
||||
},
|
||||
error => {
|
||||
this.installingExtensions.delete(key);
|
||||
onDidInstallExtensionFailure(extension, operation, error);
|
||||
errorCallback(error);
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
this.installingExtensions.delete(key);
|
||||
onDidInstallExtensionFailure(extension, operation, error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return cancellablePromise;
|
||||
}
|
||||
|
||||
private async checkAndGetCompatibleVersion(extension: IGalleryExtension): Promise<IGalleryExtension> {
|
||||
if (await this.isMalicious(extension)) {
|
||||
return Promise.reject(new ExtensionManagementError(nls.localize('malicious extension', "Can't install extension since it was reported to be problematic."), INSTALL_ERROR_MALICIOUS));
|
||||
throw new ExtensionManagementError(nls.localize('malicious extension', "Can't install extension since it was reported to be problematic."), INSTALL_ERROR_MALICIOUS);
|
||||
}
|
||||
|
||||
const compatibleExtension = await this.galleryService.getCompatibleExtension(extension);
|
||||
|
||||
if (!compatibleExtension) {
|
||||
return Promise.reject(new ExtensionManagementError(nls.localize('notFoundCompatibleDependency', "Unable to install '{0}' extension because it is not compatible with the current version of VS Code (version {1}).", extension.identifier.id, product.version), INSTALL_ERROR_INCOMPATIBLE));
|
||||
throw new ExtensionManagementError(nls.localize('notFoundCompatibleDependency', "Unable to install '{0}' extension because it is not compatible with the current version of VS Code (version {1}).", extension.identifier.id, product.version), INSTALL_ERROR_INCOMPATIBLE);
|
||||
}
|
||||
|
||||
return compatibleExtension;
|
||||
}
|
||||
|
||||
reinstallFromGallery(extension: ILocalExtension): Promise<void> {
|
||||
async reinstallFromGallery(extension: ILocalExtension): Promise<void> {
|
||||
this.logService.trace('ExtensionManagementService#reinstallFromGallery', extension.identifier.id);
|
||||
if (!this.galleryService.isEnabled()) {
|
||||
return Promise.reject(new Error(nls.localize('MarketPlaceDisabled', "Marketplace is not enabled")));
|
||||
throw new Error(nls.localize('MarketPlaceDisabled', "Marketplace is not enabled"));
|
||||
}
|
||||
return this.findGalleryExtension(extension)
|
||||
.then(galleryExtension => {
|
||||
if (galleryExtension) {
|
||||
return this.setUninstalled(extension)
|
||||
.then(() => this.extensionsScanner.removeUninstalledExtension(extension)
|
||||
.then(
|
||||
() => this.installFromGallery(galleryExtension).then(),
|
||||
e => Promise.reject(new Error(nls.localize('removeError', "Error while removing the extension: {0}. Please Quit and Start VS Code before trying again.", toErrorMessage(e))))));
|
||||
}
|
||||
return Promise.reject(new Error(nls.localize('Not a Marketplace extension', "Only Marketplace Extensions can be reinstalled")));
|
||||
});
|
||||
|
||||
const galleryExtension = await this.findGalleryExtension(extension);
|
||||
if (!galleryExtension) {
|
||||
throw new Error(nls.localize('Not a Marketplace extension', "Only Marketplace Extensions can be reinstalled"));
|
||||
}
|
||||
|
||||
await this.setUninstalled(extension);
|
||||
try {
|
||||
await this.extensionsScanner.removeUninstalledExtension(extension);
|
||||
} catch (e) {
|
||||
throw new Error(nls.localize('removeError', "Error while removing the extension: {0}. Please Quit and Start VS Code before trying again.", toErrorMessage(e)));
|
||||
}
|
||||
|
||||
await this.installFromGallery(galleryExtension);
|
||||
}
|
||||
|
||||
private getTelemetryEvent(operation: InstallOperation): string {
|
||||
return operation === InstallOperation.Update ? 'extensionGallery:update' : 'extensionGallery:install';
|
||||
}
|
||||
|
||||
private isMalicious(extension: IGalleryExtension): Promise<boolean> {
|
||||
return this.getExtensionsReport()
|
||||
.then(report => getMaliciousExtensionsSet(report).has(extension.identifier.id));
|
||||
private async isMalicious(extension: IGalleryExtension): Promise<boolean> {
|
||||
const report = await this.getExtensionsReport();
|
||||
return getMaliciousExtensionsSet(report).has(extension.identifier.id);
|
||||
}
|
||||
|
||||
private downloadInstallableExtension(extension: IGalleryExtension, operation: InstallOperation): Promise<Required<InstallableExtension>> {
|
||||
private async downloadInstallableExtension(extension: IGalleryExtension, operation: InstallOperation): Promise<Required<InstallableExtension>> {
|
||||
const metadata = <IGalleryMetadata>{
|
||||
id: extension.identifier.uuid,
|
||||
publisherId: extension.publisherId,
|
||||
publisherDisplayName: extension.publisherDisplayName,
|
||||
};
|
||||
|
||||
this.logService.trace('Started downloading extension:', extension.identifier.id);
|
||||
return this.extensionsDownloader.downloadExtension(extension, operation)
|
||||
.then(
|
||||
zip => {
|
||||
const zipPath = zip.fsPath;
|
||||
this.logService.info('Downloaded extension:', extension.identifier.id, zipPath);
|
||||
return getManifest(zipPath)
|
||||
.then(
|
||||
manifest => (<Required<InstallableExtension>>{ zipPath, identifierWithVersion: new ExtensionIdentifierWithVersion(extension.identifier, manifest.version), metadata }),
|
||||
error => Promise.reject(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_VALIDATING))
|
||||
);
|
||||
},
|
||||
error => Promise.reject(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_DOWNLOADING)));
|
||||
let zipPath;
|
||||
try {
|
||||
this.logService.trace('Started downloading extension:', extension.identifier.id);
|
||||
const zip = await this.extensionsDownloader.downloadExtension(extension, operation);
|
||||
this.logService.info('Downloaded extension:', extension.identifier.id, zipPath);
|
||||
zipPath = zip.fsPath;
|
||||
} catch (error) {
|
||||
throw new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_DOWNLOADING);
|
||||
}
|
||||
|
||||
try {
|
||||
const manifest = await getManifest(zipPath);
|
||||
return (<Required<InstallableExtension>>{ zipPath, identifierWithVersion: new ExtensionIdentifierWithVersion(extension.identifier, manifest.version), metadata });
|
||||
} catch (error) {
|
||||
throw new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_VALIDATING);
|
||||
}
|
||||
}
|
||||
|
||||
private installExtension(installableExtension: InstallableExtension, token: CancellationToken): Promise<ILocalExtension> {
|
||||
return this.unsetUninstalledAndGetLocal(installableExtension.identifierWithVersion)
|
||||
.then(
|
||||
local => {
|
||||
if (local) {
|
||||
return local;
|
||||
}
|
||||
return this.extractAndInstall(installableExtension, token);
|
||||
},
|
||||
e => {
|
||||
if (isMacintosh) {
|
||||
return Promise.reject(new ExtensionManagementError(nls.localize('quitCode', "Unable to install the extension. Please Quit and Start VS Code before reinstalling."), INSTALL_ERROR_UNSET_UNINSTALLED));
|
||||
}
|
||||
return Promise.reject(new ExtensionManagementError(nls.localize('exitCode', "Unable to install the extension. Please Exit and Start VS Code before reinstalling."), INSTALL_ERROR_UNSET_UNINSTALLED));
|
||||
});
|
||||
private async installExtension(installableExtension: InstallableExtension, token: CancellationToken): Promise<ILocalExtension> {
|
||||
try {
|
||||
const local = await this.unsetUninstalledAndGetLocal(installableExtension.identifierWithVersion);
|
||||
if (local) {
|
||||
return local;
|
||||
}
|
||||
} catch (e) {
|
||||
if (isMacintosh) {
|
||||
throw new ExtensionManagementError(nls.localize('quitCode', "Unable to install the extension. Please Quit and Start VS Code before reinstalling."), INSTALL_ERROR_UNSET_UNINSTALLED);
|
||||
} else {
|
||||
throw new ExtensionManagementError(nls.localize('exitCode', "Unable to install the extension. Please Exit and Start VS Code before reinstalling."), INSTALL_ERROR_UNSET_UNINSTALLED);
|
||||
}
|
||||
}
|
||||
return this.extractAndInstall(installableExtension, token);
|
||||
}
|
||||
|
||||
private unsetUninstalledAndGetLocal(identifierWithVersion: ExtensionIdentifierWithVersion): Promise<ILocalExtension | null> {
|
||||
return this.isUninstalled(identifierWithVersion)
|
||||
.then<ILocalExtension | null>(isUninstalled => {
|
||||
if (isUninstalled) {
|
||||
this.logService.trace('Removing the extension from uninstalled list:', identifierWithVersion.identifier.id);
|
||||
// If the same version of extension is marked as uninstalled, remove it from there and return the local.
|
||||
return this.unsetUninstalled(identifierWithVersion)
|
||||
.then(() => {
|
||||
this.logService.info('Removed the extension from uninstalled list:', identifierWithVersion.identifier.id);
|
||||
return this.getInstalled(ExtensionType.User);
|
||||
})
|
||||
.then(installed => installed.filter(i => new ExtensionIdentifierWithVersion(i.identifier, i.manifest.version).equals(identifierWithVersion))[0]);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
private async unsetUninstalledAndGetLocal(identifierWithVersion: ExtensionIdentifierWithVersion): Promise<ILocalExtension | null> {
|
||||
const isUninstalled = await this.isUninstalled(identifierWithVersion);
|
||||
if (!isUninstalled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
this.logService.trace('Removing the extension from uninstalled list:', identifierWithVersion.identifier.id);
|
||||
// If the same version of extension is marked as uninstalled, remove it from there and return the local.
|
||||
await this.unsetUninstalled(identifierWithVersion);
|
||||
this.logService.info('Removed the extension from uninstalled list:', identifierWithVersion.identifier.id);
|
||||
|
||||
const installed = await this.getInstalled(ExtensionType.User);
|
||||
return installed.find(i => new ExtensionIdentifierWithVersion(i.identifier, i.manifest.version).equals(identifierWithVersion)) || null;
|
||||
}
|
||||
|
||||
private async extractAndInstall({ zipPath, identifierWithVersion, metadata }: InstallableExtension, token: CancellationToken): Promise<ILocalExtension> {
|
||||
@@ -446,57 +447,56 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
}
|
||||
|
||||
private async installDependenciesAndPackExtensions(installed: ILocalExtension, existing: ILocalExtension | undefined): Promise<void> {
|
||||
if (this.galleryService.isEnabled()) {
|
||||
const dependenciesAndPackExtensions: string[] = installed.manifest.extensionDependencies || [];
|
||||
if (installed.manifest.extensionPack) {
|
||||
for (const extension of installed.manifest.extensionPack) {
|
||||
// add only those extensions which are new in currently installed extension
|
||||
if (!(existing && existing.manifest.extensionPack && existing.manifest.extensionPack.some(old => areSameExtensions({ id: old }, { id: extension })))) {
|
||||
if (dependenciesAndPackExtensions.every(e => !areSameExtensions({ id: e }, { id: extension }))) {
|
||||
dependenciesAndPackExtensions.push(extension);
|
||||
}
|
||||
if (!this.galleryService.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
const dependenciesAndPackExtensions: string[] = installed.manifest.extensionDependencies || [];
|
||||
if (installed.manifest.extensionPack) {
|
||||
for (const extension of installed.manifest.extensionPack) {
|
||||
// add only those extensions which are new in currently installed extension
|
||||
if (!(existing && existing.manifest.extensionPack && existing.manifest.extensionPack.some(old => areSameExtensions({ id: old }, { id: extension })))) {
|
||||
if (dependenciesAndPackExtensions.every(e => !areSameExtensions({ id: e }, { id: extension }))) {
|
||||
dependenciesAndPackExtensions.push(extension);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dependenciesAndPackExtensions.length) {
|
||||
return this.getInstalled()
|
||||
.then(installed => {
|
||||
// filter out installed extensions
|
||||
const names = dependenciesAndPackExtensions.filter(id => installed.every(({ identifier: galleryIdentifier }) => !areSameExtensions(galleryIdentifier, { id })));
|
||||
if (names.length) {
|
||||
return this.galleryService.query({ names, pageSize: dependenciesAndPackExtensions.length }, CancellationToken.None)
|
||||
.then(galleryResult => {
|
||||
const extensionsToInstall = galleryResult.firstPage;
|
||||
return Promise.all(extensionsToInstall.map(e => this.installFromGallery(e)))
|
||||
.then(undefined, errors => this.rollback(extensionsToInstall).then(() => Promise.reject(errors), () => Promise.reject(errors)));
|
||||
});
|
||||
}
|
||||
return undefined; // {{SQL CARBON EDIT}} strict-null-checks
|
||||
});
|
||||
}
|
||||
if (dependenciesAndPackExtensions.length) {
|
||||
const installed = await this.getInstalled();
|
||||
// filter out installed extensions
|
||||
const names = dependenciesAndPackExtensions.filter(id => installed.every(({ identifier: galleryIdentifier }) => !areSameExtensions(galleryIdentifier, { id })));
|
||||
if (names.length) {
|
||||
const galleryResult = await this.galleryService.query({ names, pageSize: dependenciesAndPackExtensions.length }, CancellationToken.None);
|
||||
const extensionsToInstall = galleryResult.firstPage;
|
||||
try {
|
||||
await Promise.all(extensionsToInstall.map(e => this.installFromGallery(e)));
|
||||
} catch (error) {
|
||||
try { await this.rollback(extensionsToInstall); } catch (e) { /* ignore */ }
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
private rollback(extensions: IGalleryExtension[]): Promise<void> {
|
||||
return this.getInstalled(ExtensionType.User)
|
||||
.then(installed =>
|
||||
Promise.all(installed.filter(local => extensions.some(galleryExtension => new ExtensionIdentifierWithVersion(local.identifier, local.manifest.version).equals(new ExtensionIdentifierWithVersion(galleryExtension.identifier, galleryExtension.version)))) // Check with version because we want to rollback the exact version
|
||||
.map(local => this.uninstall(local))))
|
||||
.then(() => undefined, () => undefined);
|
||||
private async rollback(extensions: IGalleryExtension[]): Promise<void> {
|
||||
const installed = await this.getInstalled(ExtensionType.User);
|
||||
const extensionsToUninstall = installed.filter(local => extensions.some(galleryExtension => new ExtensionIdentifierWithVersion(local.identifier, local.manifest.version).equals(new ExtensionIdentifierWithVersion(galleryExtension.identifier, galleryExtension.version)))); // Check with version because we want to rollback the exact version
|
||||
await Promise.all(extensionsToUninstall.map(local => this.uninstall(local)));
|
||||
}
|
||||
|
||||
uninstall(extension: ILocalExtension): Promise<void> {
|
||||
async uninstall(extension: ILocalExtension): Promise<void> {
|
||||
this.logService.trace('ExtensionManagementService#uninstall', extension.identifier.id);
|
||||
return this.toNonCancellablePromise(this.getInstalled(ExtensionType.User)
|
||||
.then(installed => {
|
||||
const extensionToUninstall = installed.filter(e => areSameExtensions(e.identifier, extension.identifier))[0];
|
||||
if (extensionToUninstall) {
|
||||
return this.checkForDependenciesAndUninstall(extensionToUninstall, installed).then(undefined, error => Promise.reject(this.joinErrors(error)));
|
||||
} else {
|
||||
return Promise.reject(new Error(nls.localize('notInstalled', "Extension '{0}' is not installed.", extension.manifest.displayName || extension.manifest.name)));
|
||||
}
|
||||
}));
|
||||
const installed = await this.getInstalled(ExtensionType.User);
|
||||
const extensionToUninstall = installed.find(e => areSameExtensions(e.identifier, extension.identifier));
|
||||
if (!extensionToUninstall) {
|
||||
throw new Error(nls.localize('notInstalled', "Extension '{0}' is not installed.", extension.manifest.displayName || extension.manifest.name));
|
||||
}
|
||||
|
||||
try {
|
||||
await this.checkForDependenciesAndUninstall(extensionToUninstall, installed);
|
||||
} catch (error) {
|
||||
throw this.joinErrors(error);
|
||||
}
|
||||
}
|
||||
|
||||
async updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): Promise<ILocalExtension> {
|
||||
@@ -506,25 +506,28 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
return local;
|
||||
}
|
||||
|
||||
/*private getGalleryMetadata(extensionName: string): Promise<IGalleryMetadata | undefined> { {{SQL CARBON EDIT}}
|
||||
return this.findGalleryExtensionByName(extensionName)
|
||||
.then(galleryExtension => galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : undefined);
|
||||
// {{ SQL CARBON EDIT }}
|
||||
/*private async getGalleryMetadata(extensionName: string): Promise<IGalleryMetadata | undefined> {
|
||||
const galleryExtension = await this.findGalleryExtensionByName(extensionName);
|
||||
return galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : undefined;
|
||||
}*/
|
||||
|
||||
private findGalleryExtension(local: ILocalExtension): Promise<IGalleryExtension> {
|
||||
private async findGalleryExtension(local: ILocalExtension): Promise<IGalleryExtension> {
|
||||
if (local.identifier.uuid) {
|
||||
return this.findGalleryExtensionById(local.identifier.uuid)
|
||||
.then(galleryExtension => galleryExtension ? galleryExtension : this.findGalleryExtensionByName(local.identifier.id));
|
||||
const galleryExtension = await this.findGalleryExtensionById(local.identifier.uuid);
|
||||
return galleryExtension ? galleryExtension : this.findGalleryExtensionByName(local.identifier.id);
|
||||
}
|
||||
return this.findGalleryExtensionByName(local.identifier.id);
|
||||
}
|
||||
|
||||
private findGalleryExtensionById(uuid: string): Promise<IGalleryExtension> {
|
||||
return this.galleryService.query({ ids: [uuid], pageSize: 1 }, CancellationToken.None).then(galleryResult => galleryResult.firstPage[0]);
|
||||
private async findGalleryExtensionById(uuid: string): Promise<IGalleryExtension> {
|
||||
const galleryResult = await this.galleryService.query({ ids: [uuid], pageSize: 1 }, CancellationToken.None);
|
||||
return galleryResult.firstPage[0];
|
||||
}
|
||||
|
||||
private findGalleryExtensionByName(name: string): Promise<IGalleryExtension> {
|
||||
return this.galleryService.query({ names: [name], pageSize: 1 }, CancellationToken.None).then(galleryResult => galleryResult.firstPage[0]);
|
||||
private async findGalleryExtensionByName(name: string): Promise<IGalleryExtension> {
|
||||
const galleryResult = await this.galleryService.query({ names: [name], pageSize: 1 }, CancellationToken.None);
|
||||
return galleryResult.firstPage[0];
|
||||
}
|
||||
|
||||
private joinErrors(errorOrErrors: (Error | string) | (Array<Error | string>)): Error {
|
||||
@@ -537,20 +540,20 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
}, new Error(''));
|
||||
}
|
||||
|
||||
private checkForDependenciesAndUninstall(extension: ILocalExtension, installed: ILocalExtension[]): Promise<void> {
|
||||
return this.preUninstallExtension(extension)
|
||||
.then(() => {
|
||||
const packedExtensions = this.getAllPackExtensionsToUninstall(extension, installed);
|
||||
if (packedExtensions.length) {
|
||||
return this.uninstallExtensions(extension, packedExtensions, installed);
|
||||
}
|
||||
return this.uninstallExtensions(extension, [], installed);
|
||||
})
|
||||
.then(() => this.postUninstallExtension(extension),
|
||||
error => {
|
||||
this.postUninstallExtension(extension, new ExtensionManagementError(error instanceof Error ? error.message : error, INSTALL_ERROR_LOCAL));
|
||||
return Promise.reject(error);
|
||||
});
|
||||
private async checkForDependenciesAndUninstall(extension: ILocalExtension, installed: ILocalExtension[]): Promise<void> {
|
||||
try {
|
||||
await this.preUninstallExtension(extension);
|
||||
const packedExtensions = this.getAllPackExtensionsToUninstall(extension, installed);
|
||||
if (packedExtensions.length) {
|
||||
await this.uninstallExtensions(extension, packedExtensions, installed);
|
||||
} else {
|
||||
await this.uninstallExtensions(extension, [], installed);
|
||||
}
|
||||
} catch (error) {
|
||||
await this.postUninstallExtension(extension, new ExtensionManagementError(error instanceof Error ? error.message : error, INSTALL_ERROR_LOCAL));
|
||||
throw error;
|
||||
}
|
||||
await this.postUninstallExtension(extension);
|
||||
}
|
||||
|
||||
private async uninstallExtensions(extension: ILocalExtension, otherExtensionsToUninstall: ILocalExtension[], installed: ILocalExtension[]): Promise<void> {
|
||||
@@ -621,33 +624,36 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
return installed.filter(e => e.manifest.extensionDependencies && e.manifest.extensionDependencies.some(id => areSameExtensions({ id }, extension.identifier)));
|
||||
}
|
||||
|
||||
private doUninstall(extension: ILocalExtension): Promise<void> {
|
||||
return this.preUninstallExtension(extension)
|
||||
.then(() => this.uninstallExtension(extension))
|
||||
.then(() => this.postUninstallExtension(extension),
|
||||
error => {
|
||||
this.postUninstallExtension(extension, new ExtensionManagementError(error instanceof Error ? error.message : error, INSTALL_ERROR_LOCAL));
|
||||
return Promise.reject(error);
|
||||
});
|
||||
private async doUninstall(extension: ILocalExtension): Promise<void> {
|
||||
try {
|
||||
await this.preUninstallExtension(extension);
|
||||
await this.uninstallExtension(extension);
|
||||
} catch (error) {
|
||||
await this.postUninstallExtension(extension, new ExtensionManagementError(error instanceof Error ? error.message : error, INSTALL_ERROR_LOCAL));
|
||||
throw error;
|
||||
}
|
||||
await this.postUninstallExtension(extension);
|
||||
}
|
||||
|
||||
private preUninstallExtension(extension: ILocalExtension): Promise<void> {
|
||||
return Promise.resolve(pfs.exists(extension.location.fsPath))
|
||||
.then(exists => exists ? null : Promise.reject(new Error(nls.localize('notExists', "Could not find extension"))))
|
||||
.then(() => {
|
||||
this.logService.info('Uninstalling extension:', extension.identifier.id);
|
||||
this._onUninstallExtension.fire(extension.identifier);
|
||||
});
|
||||
private async preUninstallExtension(extension: ILocalExtension): Promise<void> {
|
||||
const exists = await pfs.exists(extension.location.fsPath);
|
||||
if (!exists) {
|
||||
throw new Error(nls.localize('notExists', "Could not find extension"));
|
||||
}
|
||||
this.logService.info('Uninstalling extension:', extension.identifier.id);
|
||||
this._onUninstallExtension.fire(extension.identifier);
|
||||
}
|
||||
|
||||
private uninstallExtension(local: ILocalExtension): Promise<void> {
|
||||
private async uninstallExtension(local: ILocalExtension): Promise<void> {
|
||||
let promise = this.uninstallingExtensions.get(local.identifier.id);
|
||||
if (!promise) {
|
||||
// Set all versions of the extension as uninstalled
|
||||
promise = createCancelablePromise(token => this.extensionsScanner.scanUserExtensions(false)
|
||||
.then(userExtensions => this.setUninstalled(...userExtensions.filter(u => areSameExtensions(u.identifier, local.identifier))))
|
||||
.then(() => { this.uninstallingExtensions.delete(local.identifier.id); }));
|
||||
promise = createCancelablePromise(async () => {
|
||||
const userExtensions = await this.extensionsScanner.scanUserExtensions(false);
|
||||
await this.setUninstalled(...userExtensions.filter(u => areSameExtensions(u.identifier, local.identifier)));
|
||||
});
|
||||
this.uninstallingExtensions.set(local.identifier.id, promise);
|
||||
promise.finally(() => this.uninstallingExtensions.delete(local.identifier.id));
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
@@ -659,7 +665,9 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
this.logService.info('Successfully uninstalled extension:', extension.identifier.id);
|
||||
// only report if extension has a mapped gallery extension. UUID identifies the gallery extension.
|
||||
if (extension.identifier.uuid) {
|
||||
await this.galleryService.reportStatistic(extension.manifest.publisher, extension.manifest.name, extension.manifest.version, StatisticType.Uninstall);
|
||||
try {
|
||||
await this.galleryService.reportStatistic(extension.manifest.publisher, extension.manifest.name, extension.manifest.version, StatisticType.Uninstall);
|
||||
} catch (error) { /* ignore */ }
|
||||
}
|
||||
}
|
||||
this.reportTelemetry('extensionGallery:uninstall', getLocalExtensionTelemetryData(extension), undefined, error);
|
||||
@@ -675,8 +683,9 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
return this.extensionsScanner.cleanUp();
|
||||
}
|
||||
|
||||
private isUninstalled(identifier: ExtensionIdentifierWithVersion): Promise<boolean> {
|
||||
return this.filterUninstalled(identifier).then(uninstalled => uninstalled.length === 1);
|
||||
private async isUninstalled(identifier: ExtensionIdentifierWithVersion): Promise<boolean> {
|
||||
const uninstalled = await this.filterUninstalled(identifier);
|
||||
return uninstalled.length === 1;
|
||||
}
|
||||
|
||||
private filterUninstalled(...identifiers: ExtensionIdentifierWithVersion[]): Promise<string[]> {
|
||||
@@ -693,7 +702,10 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
|
||||
private setUninstalled(...extensions: ILocalExtension[]): Promise<{ [id: string]: boolean }> {
|
||||
const ids: ExtensionIdentifierWithVersion[] = extensions.map(e => new ExtensionIdentifierWithVersion(e.identifier, e.manifest.version));
|
||||
return this.extensionsScanner.withUninstalledExtensions(uninstalled => assign(uninstalled, ids.reduce((result, id) => { result[id.key()] = true; return result; }, {} as { [id: string]: boolean })));
|
||||
return this.extensionsScanner.withUninstalledExtensions(uninstalled => {
|
||||
ids.forEach(id => uninstalled[id.key()] = true);
|
||||
return uninstalled;
|
||||
});
|
||||
}
|
||||
|
||||
private unsetUninstalled(extensionIdentifier: ExtensionIdentifierWithVersion): Promise<void> {
|
||||
@@ -711,21 +723,16 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
return this.reportedExtensions;
|
||||
}
|
||||
|
||||
private updateReportCache(): Promise<IReportedExtension[]> {
|
||||
this.logService.trace('ExtensionManagementService.refreshReportedCache');
|
||||
|
||||
return this.galleryService.getExtensionsReport()
|
||||
.then(result => {
|
||||
this.logService.trace(`ExtensionManagementService.refreshReportedCache - got ${result.length} reported extensions from service`);
|
||||
return result;
|
||||
}, err => {
|
||||
this.logService.trace('ExtensionManagementService.refreshReportedCache - failed to get extension report');
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
private toNonCancellablePromise<T>(promise: Promise<T>): Promise<T> {
|
||||
return new Promise((c, e) => promise.then(result => c(result), error => e(error)));
|
||||
private async updateReportCache(): Promise<IReportedExtension[]> {
|
||||
try {
|
||||
this.logService.trace('ExtensionManagementService.refreshReportedCache');
|
||||
const result = await this.galleryService.getExtensionsReport();
|
||||
this.logService.trace(`ExtensionManagementService.refreshReportedCache - got ${result.length} reported extensions from service`);
|
||||
return result;
|
||||
} catch (err) {
|
||||
this.logService.trace('ExtensionManagementService.refreshReportedCache - failed to get extension report');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private reportTelemetry(eventName: string, extensionData: any, duration?: number, error?: Error): void {
|
||||
@@ -761,6 +768,6 @@ export class ExtensionManagementService extends Disposable implements IExtension
|
||||
]
|
||||
}
|
||||
*/
|
||||
this.telemetryService.publicLogError(eventName, assign(extensionData, { success: !error, duration, errorcode }));
|
||||
this.telemetryService.publicLogError(eventName, { ...extensionData, success: !error, duration, errorcode });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user