mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-10 18:22:34 -05:00
Merge VS Code 1.21 source code (#1067)
* Initial VS Code 1.21 file copy with patches * A few more merges * Post npm install * Fix batch of build breaks * Fix more build breaks * Fix more build errors * Fix more build breaks * Runtime fixes 1 * Get connection dialog working with some todos * Fix a few packaging issues * Copy several node_modules to package build to fix loader issues * Fix breaks from master * A few more fixes * Make tests pass * First pass of license header updates * Second pass of license header updates * Fix restore dialog issues * Remove add additional themes menu items * fix select box issues where the list doesn't show up * formatting * Fix editor dispose issue * Copy over node modules to correct location on all platforms
This commit is contained in:
@@ -10,8 +10,8 @@ import * as path from 'path';
|
||||
import * as pfs from 'vs/base/node/pfs';
|
||||
import * as errors from 'vs/base/common/errors';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { flatten, distinct } from 'vs/base/common/arrays';
|
||||
import { toDisposable, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { flatten, distinct, coalesce } from 'vs/base/common/arrays';
|
||||
import { extract, buffer } from 'vs/base/node/zip';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import {
|
||||
@@ -22,32 +22,38 @@ import {
|
||||
IExtensionIdentifier,
|
||||
IReportedExtension
|
||||
} from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { getGalleryExtensionIdFromLocal, adoptToGalleryExtensionId, areSameExtensions, getGalleryExtensionId, getMaliciousExtensionsSet } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
|
||||
import { getIdAndVersionFromLocalExtensionId } from 'vs/platform/extensionManagement/node/extensionManagementUtil';
|
||||
import { getGalleryExtensionIdFromLocal, adoptToGalleryExtensionId, areSameExtensions, getGalleryExtensionId, groupByExtension, getMaliciousExtensionsSet, getLocalExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
|
||||
import { localizeManifest } from '../common/extensionNls';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { Limiter } from 'vs/base/common/async';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import * as semver from 'semver';
|
||||
import { groupBy, values } from 'vs/base/common/collections';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { IChoiceService, Severity } from 'vs/platform/message/common/message';
|
||||
import pkg from 'vs/platform/node/package';
|
||||
import { isMacintosh } from 'vs/base/common/platform';
|
||||
import { MANIFEST_CACHE_FOLDER, USER_MANIFEST_CACHE_FILE } from 'vs/platform/extensions/common/extensions';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { ExtensionsManifestCache } from 'vs/platform/extensionManagement/node/extensionsManifestCache';
|
||||
import { IChoiceService } from 'vs/platform/dialogs/common/dialogs';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { ExtensionsLifecycle } from 'vs/platform/extensionManagement/node/extensionLifecycle';
|
||||
import { toErrorMessage } from 'vs/base/common/errorMessage';
|
||||
|
||||
const SystemExtensionsRoot = path.normalize(path.join(URI.parse(require.toUrl('')).fsPath, '..', 'extensions'));
|
||||
const INSTALL_ERROR_OBSOLETE = 'obsolete';
|
||||
const ERROR_SCANNING_SYS_EXTENSIONS = 'scanningSystem';
|
||||
const ERROR_SCANNING_USER_EXTENSIONS = 'scanningUser';
|
||||
const INSTALL_ERROR_UNSET_UNINSTALLED = 'unsetUninstalled';
|
||||
const INSTALL_ERROR_INCOMPATIBLE = 'incompatible';
|
||||
const INSTALL_ERROR_DOWNLOADING = 'downloading';
|
||||
const INSTALL_ERROR_VALIDATING = 'validating';
|
||||
const INSTALL_ERROR_GALLERY = 'gallery';
|
||||
const INSTALL_ERROR_LOCAL = 'local';
|
||||
const INSTALL_ERROR_EXTRACTING = 'extracting';
|
||||
const INSTALL_ERROR_DELETING = 'deleting';
|
||||
const INSTALL_ERROR_READING_EXTENSION_FROM_DISK = 'readingExtension';
|
||||
const INSTALL_ERROR_SAVING_METADATA = 'savingMetadata';
|
||||
const INSTALL_ERROR_UNKNOWN = 'unknown';
|
||||
|
||||
export class InstallationError extends Error {
|
||||
export class ExtensionManagementError extends Error {
|
||||
constructor(message: string, readonly code: string) {
|
||||
super(message);
|
||||
}
|
||||
@@ -93,91 +99,99 @@ interface InstallableExtension {
|
||||
zipPath: string;
|
||||
id: string;
|
||||
metadata?: IGalleryMetadata;
|
||||
current?: ILocalExtension;
|
||||
}
|
||||
|
||||
export class ExtensionManagementService implements IExtensionManagementService {
|
||||
export class ExtensionManagementService extends Disposable implements IExtensionManagementService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
private extensionsPath: string;
|
||||
private obsoletePath: string;
|
||||
private obsoleteFileLimiter: Limiter<void>;
|
||||
private uninstalledPath: string;
|
||||
private uninstalledFileLimiter: Limiter<void>;
|
||||
private reportedExtensions: TPromise<IReportedExtension[]> | undefined;
|
||||
private lastReportTimestamp = 0;
|
||||
private disposables: IDisposable[] = [];
|
||||
private readonly installingExtensions: Map<string, TPromise<ILocalExtension>> = new Map<string, TPromise<ILocalExtension>>();
|
||||
private readonly manifestCache: ExtensionsManifestCache;
|
||||
private readonly extensionLifecycle: ExtensionsLifecycle;
|
||||
|
||||
private _onInstallExtension = new Emitter<InstallExtensionEvent>();
|
||||
onInstallExtension: Event<InstallExtensionEvent> = this._onInstallExtension.event;
|
||||
private readonly _onInstallExtension = new Emitter<InstallExtensionEvent>();
|
||||
readonly onInstallExtension: Event<InstallExtensionEvent> = this._onInstallExtension.event;
|
||||
|
||||
private _onDidInstallExtension = new Emitter<DidInstallExtensionEvent>();
|
||||
onDidInstallExtension: Event<DidInstallExtensionEvent> = this._onDidInstallExtension.event;
|
||||
private readonly _onDidInstallExtension = new Emitter<DidInstallExtensionEvent>();
|
||||
readonly onDidInstallExtension: Event<DidInstallExtensionEvent> = this._onDidInstallExtension.event;
|
||||
|
||||
private _onUninstallExtension = new Emitter<IExtensionIdentifier>();
|
||||
onUninstallExtension: Event<IExtensionIdentifier> = this._onUninstallExtension.event;
|
||||
private readonly _onUninstallExtension = new Emitter<IExtensionIdentifier>();
|
||||
readonly onUninstallExtension: Event<IExtensionIdentifier> = this._onUninstallExtension.event;
|
||||
|
||||
private _onDidUninstallExtension = new Emitter<DidUninstallExtensionEvent>();
|
||||
onDidUninstallExtension: Event<DidUninstallExtensionEvent> = this._onDidUninstallExtension.event;
|
||||
|
||||
constructor(
|
||||
@IEnvironmentService private environmentService: IEnvironmentService,
|
||||
@IEnvironmentService environmentService: IEnvironmentService,
|
||||
@IChoiceService private choiceService: IChoiceService,
|
||||
@IExtensionGalleryService private galleryService: IExtensionGalleryService,
|
||||
@ILogService private logService: ILogService
|
||||
) {
|
||||
super();
|
||||
this.extensionsPath = environmentService.extensionsPath;
|
||||
this.obsoletePath = path.join(this.extensionsPath, '.obsolete');
|
||||
this.obsoleteFileLimiter = new Limiter(1);
|
||||
}
|
||||
|
||||
private deleteExtensionsManifestCache(): void {
|
||||
const cacheFolder = path.join(this.environmentService.userDataPath, MANIFEST_CACHE_FOLDER);
|
||||
const cacheFile = path.join(cacheFolder, USER_MANIFEST_CACHE_FILE);
|
||||
|
||||
pfs.del(cacheFile).done(() => { }, () => { });
|
||||
this.uninstalledPath = path.join(this.extensionsPath, '.obsolete');
|
||||
this.uninstalledFileLimiter = new Limiter(1);
|
||||
this._register(toDisposable(() => this.installingExtensions.clear()));
|
||||
this.manifestCache = this._register(new ExtensionsManifestCache(environmentService, this));
|
||||
this.extensionLifecycle = this._register(new ExtensionsLifecycle(this.logService));
|
||||
}
|
||||
|
||||
install(zipPath: string): TPromise<void> {
|
||||
this.deleteExtensionsManifestCache();
|
||||
|
||||
zipPath = path.resolve(zipPath);
|
||||
|
||||
return validateLocalExtension(zipPath)
|
||||
.then(manifest => {
|
||||
const identifier = { id: getLocalExtensionIdFromManifest(manifest) };
|
||||
return this.isObsolete(identifier.id)
|
||||
.then(isObsolete => {
|
||||
if (isObsolete) {
|
||||
return TPromise.wrapError(new Error(nls.localize('restartCodeLocal', "Please restart Code before reinstalling {0}.", manifest.displayName || manifest.name)));
|
||||
}
|
||||
return this.checkOutdated(manifest)
|
||||
.then(validated => {
|
||||
if (validated) {
|
||||
this._onInstallExtension.fire({ identifier, zipPath });
|
||||
return this.unsetUninstalledAndRemove(identifier.id)
|
||||
.then(
|
||||
() => this.checkOutdated(manifest)
|
||||
.then(validated => {
|
||||
if (validated) {
|
||||
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, id: identifier.id, metadata: null })
|
||||
.then(
|
||||
local => this._onDidInstallExtension.fire({ identifier, zipPath, local }),
|
||||
error => { this._onDidInstallExtension.fire({ identifier, zipPath, error }); return TPromise.wrapError(error); }
|
||||
);
|
||||
/*
|
||||
return this.getMetadata(getGalleryExtensionId(manifest.publisher, manifest.name))
|
||||
.then(
|
||||
metadata => this.installFromZipPath(identifier, zipPath, metadata, manifest),
|
||||
error => this.installFromZipPath(identifier, zipPath, null, manifest));
|
||||
*/
|
||||
}
|
||||
return null;
|
||||
});
|
||||
});
|
||||
// {{SQL CARBON EDIT}}
|
||||
// Until there's a gallery for SQL Ops Studio, skip retrieving the metadata from the gallery
|
||||
return this.installExtension({ zipPath, id: identifier.id, metadata: null })
|
||||
.then(
|
||||
local => this._onDidInstallExtension.fire({ identifier, zipPath, local }),
|
||||
error => { this._onDidInstallExtension.fire({ identifier, zipPath, error }); return TPromise.wrapError(error); }
|
||||
);
|
||||
/*
|
||||
return this.getMetadata(getGalleryExtensionId(manifest.publisher, manifest.name))
|
||||
.then(
|
||||
metadata => this.installFromZipPath(identifier, zipPath, metadata, manifest),
|
||||
error => this.installFromZipPath(identifier, zipPath, null, manifest));
|
||||
*/
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
e => TPromise.wrapError(new Error(nls.localize('restartCode', "Please restart SQL Operations Studio before reinstalling {0}.", manifest.displayName || manifest.name))));
|
||||
});
|
||||
}
|
||||
|
||||
private unsetUninstalledAndRemove(id: string): TPromise<void> {
|
||||
return this.isUninstalled(id)
|
||||
.then(isUninstalled => {
|
||||
if (isUninstalled) {
|
||||
this.logService.trace('Removing the extension:', id);
|
||||
const extensionPath = path.join(this.extensionsPath, id);
|
||||
return pfs.rimraf(extensionPath)
|
||||
.then(() => this.unsetUninstalled(id))
|
||||
.then(() => this.logService.info('Removed the extension:', id));
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private checkOutdated(manifest: IExtensionManifest): TPromise<boolean> {
|
||||
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
|
||||
return this.getInstalled()
|
||||
return this.getInstalled(LocalExtensionType.User)
|
||||
.then(installedExtensions => {
|
||||
const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, { id: getGalleryExtensionIdFromLocal(local) }) && semver.gt(local.manifest.version, manifest.version))[0];
|
||||
if (newer) {
|
||||
@@ -205,8 +219,8 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
return this.getDependenciesToInstall(local.manifest.extensionDependencies)
|
||||
.then(dependenciesToInstall => this.downloadAndInstallExtensions(metadata ? dependenciesToInstall.filter(d => d.identifier.uuid !== metadata.id) : dependenciesToInstall))
|
||||
.then(() => local, error => {
|
||||
this.uninstallExtension(local.identifier);
|
||||
return TPromise.wrapError(error);
|
||||
this.uninstallExtension(local);
|
||||
return TPromise.wrapError(new Error(nls.localize('errorInstallingDependencies', "Error while installing dependencies. {0}", error instanceof Error ? error.message : error)));
|
||||
});
|
||||
}
|
||||
return local;
|
||||
@@ -218,8 +232,6 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
}
|
||||
|
||||
installFromGallery(extension: IGalleryExtension): TPromise<void> {
|
||||
this.deleteExtensionsManifestCache();
|
||||
|
||||
this.onInstallExtensions([extension]);
|
||||
return this.collectExtensionsToInstall(extension)
|
||||
.then(
|
||||
@@ -235,64 +247,67 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
error => this.onDidInstallExtensions([extension], [], [error]));
|
||||
}
|
||||
|
||||
reinstall(extension: ILocalExtension): TPromise<void> {
|
||||
if (!this.galleryService.isEnabled()) {
|
||||
return TPromise.wrapError(new Error(nls.localize('MarketPlaceDisabled', "Marketplace is not enabled")));
|
||||
}
|
||||
return this.findGalleryExtension(extension)
|
||||
.then(galleryExtension => {
|
||||
if (galleryExtension) {
|
||||
return this.uninstallExtension(extension)
|
||||
.then(() => this.removeUninstalledExtension(extension)
|
||||
.then(
|
||||
() => this.installFromGallery(galleryExtension),
|
||||
e => TPromise.wrapError(new Error(nls.localize('removeError', "Error while removing the extension: {0}. Please Quit and Start VS Code before trying again.", toErrorMessage(e))))));
|
||||
}
|
||||
return TPromise.wrapError(new Error(nls.localize('Not Market place extension', "Only Market place Extensions can be reinstalled")));
|
||||
});
|
||||
}
|
||||
|
||||
private collectExtensionsToInstall(extension: IGalleryExtension): TPromise<IGalleryExtension[]> {
|
||||
return this.galleryService.loadCompatibleVersion(extension)
|
||||
.then(compatible => {
|
||||
if (!compatible) {
|
||||
// {{SQL CARBON EDIT}}
|
||||
return TPromise.wrapError<IGalleryExtension[]>(new InstallationError(nls.localize('notFoundCompatible', "Unable to install because, the extension '{0}' compatible with current version '{1}' of SQL Operations Studio is not found.", extension.identifier.id, pkg.version), INSTALL_ERROR_INCOMPATIBLE));
|
||||
return TPromise.wrapError<IGalleryExtension[]>(new ExtensionManagementError(nls.localize('notFoundCompatible', "Unable to install because, the extension '{0}' compatible with current version '{1}' of SQL Operations Studio is not found.", extension.identifier.id, pkg.version), INSTALL_ERROR_INCOMPATIBLE));
|
||||
}
|
||||
return this.getDependenciesToInstall(compatible.properties.dependencies)
|
||||
.then(
|
||||
dependenciesToInstall => {
|
||||
const extensionsToInstall = [compatible, ...dependenciesToInstall.filter(d => d.identifier.uuid !== compatible.identifier.uuid)];
|
||||
return this.checkForObsolete(extensionsToInstall)
|
||||
.then(
|
||||
extensionsToInstall => extensionsToInstall,
|
||||
error => TPromise.wrapError<IGalleryExtension[]>(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_OBSOLETE))
|
||||
);
|
||||
},
|
||||
error => TPromise.wrapError<IGalleryExtension[]>(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_GALLERY)));
|
||||
dependenciesToInstall => ([compatible, ...dependenciesToInstall.filter(d => d.identifier.uuid !== compatible.identifier.uuid)]),
|
||||
error => TPromise.wrapError<IGalleryExtension[]>(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_GALLERY)));
|
||||
},
|
||||
error => TPromise.wrapError<IGalleryExtension[]>(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_GALLERY)));
|
||||
error => TPromise.wrapError<IGalleryExtension[]>(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_GALLERY)));
|
||||
}
|
||||
|
||||
private downloadAndInstallExtensions(extensions: IGalleryExtension[]): TPromise<ILocalExtension[]> {
|
||||
return this.getInstalled(LocalExtensionType.User)
|
||||
.then(
|
||||
installed => TPromise.join(extensions.map(extensionToInstall =>
|
||||
this.downloadAndInstallExtension(extensionToInstall, installed)
|
||||
)).then(null, errors => this.rollback(extensions).then(() => TPromise.wrapError(errors), () => TPromise.wrapError(errors))),
|
||||
error => TPromise.wrapError<ILocalExtension[]>(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_LOCAL)));
|
||||
return TPromise.join(extensions.map(extensionToInstall => this.downloadAndInstallExtension(extensionToInstall)))
|
||||
.then(null, errors => this.rollback(extensions).then(() => TPromise.wrapError(errors), () => TPromise.wrapError(errors)));
|
||||
}
|
||||
|
||||
private downloadAndInstallExtension(extensionToInstall: IGalleryExtension, installed: ILocalExtension[]): TPromise<ILocalExtension> {
|
||||
return this.getExtensionsReport().then(report => {
|
||||
if (getMaliciousExtensionsSet(report).has(extensionToInstall.identifier.id)) {
|
||||
throw new Error(nls.localize('malicious extension', "Can't install extension since it was reported to be malicious."));
|
||||
}
|
||||
|
||||
return this.downloadInstallableExtension(extensionToInstall, installed)
|
||||
.then(installableExtension => this.installExtension(installableExtension).then(null, e => TPromise.wrapError(new InstallationError(this.joinErrors(e).message, INSTALL_ERROR_EXTRACTING))));
|
||||
});
|
||||
}
|
||||
|
||||
private checkForObsolete(extensionsToInstall: IGalleryExtension[]): TPromise<IGalleryExtension[]> {
|
||||
return this.filterObsolete(...extensionsToInstall.map(i => getLocalExtensionIdFromGallery(i, i.version)))
|
||||
.then(obsolete => {
|
||||
if (obsolete.length) {
|
||||
if (isMacintosh) {
|
||||
return TPromise.wrapError<IGalleryExtension[]>(new Error(nls.localize('quitCode', "Unable to install because an obsolete instance of the extension is still running. Please Quit and Start VS Code before reinstalling.")));
|
||||
private downloadAndInstallExtension(extension: IGalleryExtension): TPromise<ILocalExtension> {
|
||||
let installingExtension = this.installingExtensions.get(extension.identifier.id);
|
||||
if (!installingExtension) {
|
||||
installingExtension = this.getExtensionsReport()
|
||||
.then(report => {
|
||||
if (getMaliciousExtensionsSet(report).has(extension.identifier.id)) {
|
||||
throw new Error(nls.localize('malicious extension', "Can't install extension since it was reported to be problematic."));
|
||||
} else {
|
||||
return extension;
|
||||
}
|
||||
return TPromise.wrapError<IGalleryExtension[]>(new Error(nls.localize('exitCode', "Unable to install because an obsolete instance of the extension is still running. Please Exit and Start VS Code before reinstalling.")));
|
||||
}
|
||||
return extensionsToInstall;
|
||||
});
|
||||
})
|
||||
.then(extension => this.downloadInstallableExtension(extension))
|
||||
.then(installableExtension => this.installExtension(installableExtension))
|
||||
.then(
|
||||
local => { this.installingExtensions.delete(extension.identifier.id); return local; },
|
||||
e => { this.installingExtensions.delete(extension.identifier.id); return TPromise.wrapError(e); }
|
||||
);
|
||||
|
||||
this.installingExtensions.set(extension.identifier.id, installingExtension);
|
||||
}
|
||||
return installingExtension;
|
||||
}
|
||||
|
||||
private downloadInstallableExtension(extension: IGalleryExtension, installed: ILocalExtension[]): TPromise<InstallableExtension> {
|
||||
const current = installed.filter(i => i.identifier.uuid === extension.identifier.uuid)[0];
|
||||
const id = getLocalExtensionIdFromGallery(extension, extension.version);
|
||||
private downloadInstallableExtension(extension: IGalleryExtension): TPromise<InstallableExtension> {
|
||||
const metadata = <IGalleryMetadata>{
|
||||
id: extension.identifier.uuid,
|
||||
publisherId: extension.publisherId,
|
||||
@@ -303,29 +318,28 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
.then(
|
||||
compatible => {
|
||||
if (compatible) {
|
||||
this.logService.trace('Started downloading extension:', extension.name);
|
||||
return this.galleryService.download(extension)
|
||||
.then(
|
||||
zipPath => validateLocalExtension(zipPath)
|
||||
.then(
|
||||
() => (<InstallableExtension>{ zipPath, id, metadata, current }),
|
||||
error => TPromise.wrapError(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_VALIDATING))
|
||||
),
|
||||
error => TPromise.wrapError(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_DOWNLOADING)));
|
||||
zipPath => {
|
||||
this.logService.info('Downloaded extension:', extension.name);
|
||||
return validateLocalExtension(zipPath)
|
||||
.then(
|
||||
manifest => (<InstallableExtension>{ zipPath, id: getLocalExtensionIdFromManifest(manifest), metadata }),
|
||||
error => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_VALIDATING))
|
||||
);
|
||||
},
|
||||
error => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_DOWNLOADING)));
|
||||
} else {
|
||||
return TPromise.wrapError<InstallableExtension>(new InstallationError(nls.localize('notFoundCompatibleDependency', "Unable to install because, the depending extension '{0}' compatible with current version '{1}' of VS Code is not found.", extension.identifier.id, pkg.version), INSTALL_ERROR_INCOMPATIBLE));
|
||||
return TPromise.wrapError<InstallableExtension>(new ExtensionManagementError(nls.localize('notFoundCompatibleDependency', "Unable to install because, the depending extension '{0}' compatible with current version '{1}' of VS Code is not found.", extension.identifier.id, pkg.version), INSTALL_ERROR_INCOMPATIBLE));
|
||||
}
|
||||
},
|
||||
error => TPromise.wrapError<InstallableExtension>(new InstallationError(this.joinErrors(error).message, INSTALL_ERROR_GALLERY)));
|
||||
}
|
||||
|
||||
private rollback(extensions: IGalleryExtension[]): TPromise<void> {
|
||||
return this.filterOutUninstalled(extensions)
|
||||
.then(installed => TPromise.join(installed.map(local => this.uninstallExtension(local.identifier))))
|
||||
.then(() => null, () => null);
|
||||
error => TPromise.wrapError<InstallableExtension>(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_GALLERY)));
|
||||
}
|
||||
|
||||
private onInstallExtensions(extensions: IGalleryExtension[]): void {
|
||||
for (const extension of extensions) {
|
||||
this.logService.info('Installing extension:', extension.name);
|
||||
const id = getLocalExtensionIdFromGallery(extension, extension.version);
|
||||
this._onInstallExtension.fire({ identifier: { id, uuid: extension.identifier.uuid }, gallery: extension });
|
||||
}
|
||||
@@ -337,9 +351,11 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
const local = locals[index];
|
||||
const error = errors[index];
|
||||
if (local) {
|
||||
this.logService.info(`Extensions installed successfully:`, gallery.identifier.id);
|
||||
this._onDidInstallExtension.fire({ identifier, gallery, local });
|
||||
} else {
|
||||
const errorCode = error && (<InstallationError>error).code ? (<InstallationError>error).code : INSTALL_ERROR_UNKNOWN;
|
||||
const errorCode = error && (<ExtensionManagementError>error).code ? (<ExtensionManagementError>error).code : INSTALL_ERROR_UNKNOWN;
|
||||
this.logService.error(`Failed to install extension:`, gallery.identifier.id, error ? error.message : errorCode);
|
||||
this._onDidInstallExtension.fire({ identifier, gallery, error: errorCode });
|
||||
}
|
||||
});
|
||||
@@ -348,73 +364,122 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
|
||||
private getDependenciesToInstall(dependencies: string[]): TPromise<IGalleryExtension[]> {
|
||||
if (dependencies.length) {
|
||||
return this.galleryService.loadAllDependencies(dependencies.map(id => (<IExtensionIdentifier>{ id })))
|
||||
.then(allDependencies => this.getInstalled()
|
||||
.then(local => {
|
||||
return allDependencies.filter(d => {
|
||||
const extensionId = getLocalExtensionIdFromGallery(d, d.version);
|
||||
return local.every(({ identifier }) => identifier.id !== extensionId);
|
||||
});
|
||||
}));
|
||||
return this.getInstalled()
|
||||
.then(installed => {
|
||||
const uninstalledDeps = dependencies.filter(d => installed.every(i => getGalleryExtensionId(i.manifest.publisher, i.manifest.name) !== d));
|
||||
if (uninstalledDeps.length) {
|
||||
return this.galleryService.loadAllDependencies(uninstalledDeps.map(id => (<IExtensionIdentifier>{ id })))
|
||||
.then(allDependencies => allDependencies.filter(d => {
|
||||
const extensionId = getLocalExtensionIdFromGallery(d, d.version);
|
||||
return installed.every(({ identifier }) => identifier.id !== extensionId);
|
||||
}));
|
||||
}
|
||||
return [];
|
||||
});
|
||||
}
|
||||
return TPromise.as([]);
|
||||
}
|
||||
|
||||
private filterOutUninstalled(extensions: IGalleryExtension[]): TPromise<ILocalExtension[]> {
|
||||
return this.getInstalled()
|
||||
.then(installed => installed.filter(local => !!this.getGalleryExtensionForLocalExtension(extensions, local)));
|
||||
private installExtension(installableExtension: InstallableExtension): TPromise<ILocalExtension> {
|
||||
return this.unsetUninstalledAndGetLocal(installableExtension.id)
|
||||
.then(
|
||||
local => {
|
||||
if (local) {
|
||||
return local;
|
||||
}
|
||||
return this.extractAndInstall(installableExtension);
|
||||
},
|
||||
e => {
|
||||
if (isMacintosh) {
|
||||
return TPromise.wrapError<ILocalExtension>(new ExtensionManagementError(nls.localize('quitCode', "Unable to install the extension. Please Quit and Start VS Code before reinstalling."), INSTALL_ERROR_UNSET_UNINSTALLED));
|
||||
}
|
||||
return TPromise.wrapError<ILocalExtension>(new ExtensionManagementError(nls.localize('exitCode', "Unable to install the extension. Please Exit and Start VS Code before reinstalling."), INSTALL_ERROR_UNSET_UNINSTALLED));
|
||||
});
|
||||
}
|
||||
|
||||
private getGalleryExtensionForLocalExtension(galleryExtensions: IGalleryExtension[], localExtension: ILocalExtension): IGalleryExtension {
|
||||
const filtered = galleryExtensions.filter(galleryExtension => areSameExtensions(localExtension.identifier, { id: getLocalExtensionIdFromGallery(galleryExtension, galleryExtension.version), uuid: galleryExtension.identifier.uuid }));
|
||||
return filtered.length ? filtered[0] : null;
|
||||
private unsetUninstalledAndGetLocal(id: string): TPromise<ILocalExtension> {
|
||||
return this.isUninstalled(id)
|
||||
.then(isUninstalled => {
|
||||
if (isUninstalled) {
|
||||
this.logService.trace('Removing the extension from uninstalled list:', id);
|
||||
// If the same version of extension is marked as uninstalled, remove it from there and return the local.
|
||||
return this.unsetUninstalled(id)
|
||||
.then(() => {
|
||||
this.logService.info('Removed the extension from uninstalled list:', id);
|
||||
return this.getInstalled(LocalExtensionType.User);
|
||||
})
|
||||
.then(installed => installed.filter(i => i.identifier.id === id)[0]);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private installExtension({ zipPath, id, metadata, current }: InstallableExtension): TPromise<ILocalExtension> {
|
||||
private extractAndInstall({ zipPath, id, metadata }: InstallableExtension): TPromise<ILocalExtension> {
|
||||
const extensionPath = path.join(this.extensionsPath, id);
|
||||
|
||||
return pfs.rimraf(extensionPath).then(() => {
|
||||
return extract(zipPath, extensionPath, { sourcePath: 'extension', overwrite: true })
|
||||
.then(() => readManifest(extensionPath))
|
||||
.then(({ manifest }) => {
|
||||
return pfs.readdir(extensionPath).then(children => {
|
||||
const readme = children.filter(child => /^readme(\.txt|\.md|)$/i.test(child))[0];
|
||||
const readmeUrl = readme ? URI.file(path.join(extensionPath, readme)).toString() : null;
|
||||
const changelog = children.filter(child => /^changelog(\.txt|\.md|)$/i.test(child))[0];
|
||||
const changelogUrl = changelog ? URI.file(path.join(extensionPath, changelog)).toString() : null;
|
||||
const type = LocalExtensionType.User;
|
||||
const identifier = { id, uuid: metadata ? metadata.id : null };
|
||||
|
||||
const local: ILocalExtension = { type, identifier, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl };
|
||||
|
||||
return this.saveMetadataForLocalExtension(local)
|
||||
.then(() => this.checkForRename(current, local))
|
||||
.then(() => local);
|
||||
return pfs.rimraf(extensionPath)
|
||||
.then(() => {
|
||||
this.logService.trace(`Started extracting the extension from ${zipPath} to ${extensionPath}`);
|
||||
return extract(zipPath, extensionPath, { sourcePath: 'extension', overwrite: true })
|
||||
.then(
|
||||
() => {
|
||||
this.logService.info(`Extracted extension to ${extensionPath}:`, id);
|
||||
return this.completeInstall(id, extensionPath, metadata);
|
||||
},
|
||||
e => TPromise.wrapError(new ExtensionManagementError(e.message, INSTALL_ERROR_EXTRACTING)))
|
||||
.then(null, e => {
|
||||
this.logService.info('Deleting the extracted extension', id);
|
||||
return pfs.rimraf(extensionPath).then(() => TPromise.wrapError(e), () => TPromise.wrapError(e));
|
||||
});
|
||||
});
|
||||
});
|
||||
}, e => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(e).message, INSTALL_ERROR_DELETING)));
|
||||
}
|
||||
|
||||
private completeInstall(id: string, extensionPath: string, metadata: IGalleryMetadata): TPromise<ILocalExtension> {
|
||||
return TPromise.join([readManifest(extensionPath), pfs.readdir(extensionPath)])
|
||||
.then(null, e => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(e).message, INSTALL_ERROR_READING_EXTENSION_FROM_DISK)))
|
||||
.then(([{ manifest }, children]) => {
|
||||
const readme = children.filter(child => /^readme(\.txt|\.md|)$/i.test(child))[0];
|
||||
const readmeUrl = readme ? URI.file(path.join(extensionPath, readme)).toString() : null;
|
||||
const changelog = children.filter(child => /^changelog(\.txt|\.md|)$/i.test(child))[0];
|
||||
const changelogUrl = changelog ? URI.file(path.join(extensionPath, changelog)).toString() : null;
|
||||
const type = LocalExtensionType.User;
|
||||
const identifier = { id, uuid: metadata ? metadata.id : null };
|
||||
|
||||
const local: ILocalExtension = { type, identifier, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl };
|
||||
|
||||
this.logService.trace(`Updating metadata of the extension:`, id);
|
||||
return this.saveMetadataForLocalExtension(local)
|
||||
.then(() => {
|
||||
this.logService.info(`Updated metadata of the extension:`, id);
|
||||
return local;
|
||||
}, e => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(e).message, INSTALL_ERROR_SAVING_METADATA)));
|
||||
});
|
||||
}
|
||||
|
||||
private rollback(extensions: IGalleryExtension[]): TPromise<void> {
|
||||
return this.getInstalled(LocalExtensionType.User)
|
||||
.then(installed =>
|
||||
TPromise.join(installed.filter(local => extensions.some(galleryExtension => local.identifier.id === getLocalExtensionIdFromGallery(galleryExtension, galleryExtension.version))) // Only check id (pub.name-version) because we want to rollback the exact version
|
||||
.map(local => this.uninstallExtension(local))))
|
||||
.then(() => null, () => null);
|
||||
}
|
||||
|
||||
uninstall(extension: ILocalExtension, force = false): TPromise<void> {
|
||||
this.deleteExtensionsManifestCache();
|
||||
|
||||
return this.removeOutdatedExtensions()
|
||||
.then(() =>
|
||||
this.scanUserExtensions()
|
||||
.then(installed => {
|
||||
const promises = installed
|
||||
.filter(e => e.manifest.publisher === extension.manifest.publisher && e.manifest.name === extension.manifest.name)
|
||||
.map(e => this.checkForDependenciesAndUninstall(e, installed, force));
|
||||
return TPromise.join(promises).then(null, error => TPromise.wrapError(this.joinErrors(error)));
|
||||
}))
|
||||
.then(() => { /* drop resolved value */ });
|
||||
return this.getInstalled(LocalExtensionType.User)
|
||||
.then(installed => {
|
||||
const promises = installed
|
||||
.filter(e => e.manifest.publisher === extension.manifest.publisher && e.manifest.name === extension.manifest.name)
|
||||
.map(e => this.checkForDependenciesAndUninstall(e, installed, force));
|
||||
return TPromise.join(promises).then(() => null, error => TPromise.wrapError(this.joinErrors(error)));
|
||||
});
|
||||
}
|
||||
|
||||
updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise<ILocalExtension> {
|
||||
this.deleteExtensionsManifestCache();
|
||||
|
||||
local.metadata = metadata;
|
||||
return this.saveMetadataForLocalExtension(local);
|
||||
return this.saveMetadataForLocalExtension(local)
|
||||
.then(localExtension => {
|
||||
this.manifestCache.invalidate();
|
||||
return localExtension;
|
||||
});
|
||||
}
|
||||
|
||||
private saveMetadataForLocalExtension(local: ILocalExtension): TPromise<ILocalExtension> {
|
||||
@@ -430,19 +495,24 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
}
|
||||
|
||||
private getMetadata(extensionName: string): TPromise<IGalleryMetadata> {
|
||||
return this.galleryService.query({ names: [extensionName], pageSize: 1 })
|
||||
.then(galleryResult => {
|
||||
const galleryExtension = galleryResult.firstPage[0];
|
||||
return galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : null;
|
||||
});
|
||||
return this.findGalleryExtensionByName(extensionName)
|
||||
.then(galleryExtension => galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : null);
|
||||
}
|
||||
|
||||
private checkForRename(currentExtension: ILocalExtension, newExtension: ILocalExtension): TPromise<void> {
|
||||
// Check if the gallery id for current and new exensions are same, if not, remove the current one.
|
||||
if (currentExtension && getGalleryExtensionIdFromLocal(currentExtension) !== getGalleryExtensionIdFromLocal(newExtension)) {
|
||||
return this.setObsolete(currentExtension.identifier.id);
|
||||
private findGalleryExtension(local: ILocalExtension): TPromise<IGalleryExtension> {
|
||||
if (local.identifier.uuid) {
|
||||
return this.findGalleryExtensionById(local.identifier.uuid)
|
||||
.then(galleryExtension => galleryExtension ? galleryExtension : this.findGalleryExtensionByName(getGalleryExtensionIdFromLocal(local)));
|
||||
}
|
||||
return TPromise.as(null);
|
||||
return this.findGalleryExtensionByName(getGalleryExtensionIdFromLocal(local));
|
||||
}
|
||||
|
||||
private findGalleryExtensionById(uuid: string): TPromise<IGalleryExtension> {
|
||||
return this.galleryService.query({ ids: [uuid], pageSize: 1 }).then(galleryResult => galleryResult.firstPage[0]);
|
||||
}
|
||||
|
||||
private findGalleryExtensionByName(name: string): TPromise<IGalleryExtension> {
|
||||
return this.galleryService.query({ names: [name], pageSize: 1 }).then(galleryResult => galleryResult.firstPage[0]);
|
||||
}
|
||||
|
||||
private joinErrors(errorOrErrors: (Error | string) | ((Error | string)[])): Error {
|
||||
@@ -484,6 +554,7 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
nls.localize('uninstallAll', "All"),
|
||||
nls.localize('cancel', "Cancel")
|
||||
];
|
||||
this.logService.info('Requesting for confirmation to uninstall extension with dependencies', extension.identifier.id);
|
||||
return this.choiceService.choose(Severity.Info, message, options, 2, true)
|
||||
.then<void>(value => {
|
||||
if (value === 0) {
|
||||
@@ -493,6 +564,7 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
const dependencies = distinct(this.getDependenciesToUninstallRecursively(extension, installed, [])).filter(e => e !== extension);
|
||||
return this.uninstallWithDependencies(extension, dependencies, installed);
|
||||
}
|
||||
this.logService.info('Cancelled uninstalling extension:', extension.identifier.id);
|
||||
return TPromise.wrapError(errors.canceled());
|
||||
}, error => TPromise.wrapError(errors.canceled()));
|
||||
}
|
||||
@@ -507,11 +579,13 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
nls.localize('ok', "OK"),
|
||||
nls.localize('cancel', "Cancel")
|
||||
];
|
||||
this.logService.info('Requesting for confirmation to uninstall extension', extension.identifier.id);
|
||||
return this.choiceService.choose(Severity.Info, message, options, 1, true)
|
||||
.then<void>(value => {
|
||||
if (value === 0) {
|
||||
return this.uninstallWithDependencies(extension, [], installed);
|
||||
}
|
||||
this.logService.info('Cancelled uninstalling extension:', extension.identifier.id);
|
||||
return TPromise.wrapError(errors.canceled());
|
||||
}, error => TPromise.wrapError(errors.canceled()));
|
||||
}
|
||||
@@ -522,7 +596,7 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
if (dependents.length) {
|
||||
return TPromise.wrapError<void>(new Error(this.getDependentsErrorMessage(extension, dependents)));
|
||||
}
|
||||
return TPromise.join([this.uninstallExtension(extension.identifier), ...dependenciesToUninstall.map(d => this.doUninstall(d))]).then(() => null);
|
||||
return TPromise.join([this.uninstallExtension(extension), ...dependenciesToUninstall.map(d => this.doUninstall(d))]).then(() => null);
|
||||
}
|
||||
|
||||
private getDependentsErrorMessage(extension: ILocalExtension, dependents: ILocalExtension[]): string {
|
||||
@@ -573,7 +647,7 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
|
||||
private doUninstall(extension: ILocalExtension): TPromise<void> {
|
||||
return this.preUninstallExtension(extension)
|
||||
.then(() => this.uninstallExtension(extension.identifier))
|
||||
.then(() => this.uninstallExtension(extension))
|
||||
.then(() => this.postUninstallExtension(extension),
|
||||
error => {
|
||||
this.postUninstallExtension(extension, INSTALL_ERROR_LOCAL);
|
||||
@@ -582,27 +656,28 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
}
|
||||
|
||||
private preUninstallExtension(extension: ILocalExtension): TPromise<void> {
|
||||
const extensionPath = path.join(this.extensionsPath, extension.identifier.id);
|
||||
return pfs.exists(extensionPath)
|
||||
return pfs.exists(extension.path)
|
||||
.then(exists => exists ? null : TPromise.wrapError(new Error(nls.localize('notExists', "Could not find extension"))))
|
||||
.then(() => this._onUninstallExtension.fire(extension.identifier));
|
||||
.then(() => {
|
||||
this.logService.info('Uninstalling extension:', extension.identifier.id);
|
||||
this._onUninstallExtension.fire(extension.identifier);
|
||||
});
|
||||
}
|
||||
|
||||
private uninstallExtension({ id }: IExtensionIdentifier): TPromise<void> {
|
||||
const extensionPath = path.join(this.extensionsPath, id);
|
||||
return this.setObsolete(id)
|
||||
.then(() => pfs.rimraf(extensionPath))
|
||||
.then(() => this.unsetObsolete(id));
|
||||
private uninstallExtension(local: ILocalExtension): TPromise<void> {
|
||||
return this.setUninstalled(local.identifier.id);
|
||||
}
|
||||
|
||||
private async postUninstallExtension(extension: ILocalExtension, error?: string): TPromise<void> {
|
||||
if (!error) {
|
||||
if (error) {
|
||||
this.logService.error('Failed to uninstall extension:', extension.identifier.id, error);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
this._onDidUninstallExtension.fire({ identifier: extension.identifier, error });
|
||||
}
|
||||
|
||||
@@ -610,141 +685,144 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
const promises = [];
|
||||
|
||||
if (type === null || type === LocalExtensionType.System) {
|
||||
promises.push(this.scanSystemExtensions());
|
||||
promises.push(this.scanSystemExtensions().then(null, e => new ExtensionManagementError(this.joinErrors(e).message, ERROR_SCANNING_SYS_EXTENSIONS)));
|
||||
}
|
||||
|
||||
if (type === null || type === LocalExtensionType.User) {
|
||||
promises.push(this.scanUserExtensions());
|
||||
promises.push(this.scanUserExtensions(true).then(null, e => new ExtensionManagementError(this.joinErrors(e).message, ERROR_SCANNING_USER_EXTENSIONS)));
|
||||
}
|
||||
|
||||
return TPromise.join<ILocalExtension[]>(promises).then(flatten);
|
||||
return TPromise.join<ILocalExtension[]>(promises).then(flatten, errors => TPromise.wrapError<ILocalExtension[]>(this.joinErrors(errors)));
|
||||
}
|
||||
|
||||
private scanSystemExtensions(): TPromise<ILocalExtension[]> {
|
||||
return this.scanExtensions(SystemExtensionsRoot, LocalExtensionType.System);
|
||||
this.logService.trace('Started scanning system extensions');
|
||||
return this.scanExtensions(SystemExtensionsRoot, LocalExtensionType.System)
|
||||
.then(result => {
|
||||
this.logService.info('Scanned system extensions:', result.length);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
private scanUserExtensions(): TPromise<ILocalExtension[]> {
|
||||
return this.scanExtensions(this.extensionsPath, LocalExtensionType.User).then(extensions => {
|
||||
const byId = values(groupBy(extensions, p => getGalleryExtensionIdFromLocal(p)));
|
||||
return byId.map(p => p.sort((a, b) => semver.rcompare(a.manifest.version, b.manifest.version))[0]);
|
||||
});
|
||||
private scanUserExtensions(excludeOutdated: boolean): TPromise<ILocalExtension[]> {
|
||||
this.logService.trace('Started scanning user extensions');
|
||||
return TPromise.join([this.getUninstalledExtensions(), this.scanExtensions(this.extensionsPath, LocalExtensionType.User)])
|
||||
.then(([uninstalled, extensions]) => {
|
||||
extensions = extensions.filter(e => !uninstalled[e.identifier.id]);
|
||||
if (excludeOutdated) {
|
||||
const byExtension: ILocalExtension[][] = groupByExtension(extensions, e => ({ id: getGalleryExtensionIdFromLocal(e), uuid: e.identifier.uuid }));
|
||||
extensions = byExtension.map(p => p.sort((a, b) => semver.rcompare(a.manifest.version, b.manifest.version))[0]);
|
||||
}
|
||||
this.logService.info('Scanned user extensions:', extensions.length);
|
||||
return extensions;
|
||||
});
|
||||
}
|
||||
|
||||
private scanExtensions(root: string, type: LocalExtensionType): TPromise<ILocalExtension[]> {
|
||||
const limiter = new Limiter(10);
|
||||
return pfs.readdir(root)
|
||||
.then(extensionsFolders => TPromise.join(extensionsFolders.map(extensionFolder => limiter.queue(() => this.scanExtension(extensionFolder, root, type)))))
|
||||
.then(extensions => coalesce(extensions));
|
||||
}
|
||||
|
||||
return this.scanExtensionFolders(root)
|
||||
.then(extensionIds => TPromise.join(extensionIds.map(id => {
|
||||
const extensionPath = path.join(root, id);
|
||||
|
||||
const each = () => pfs.readdir(extensionPath).then(children => {
|
||||
private scanExtension(folderName: string, root: string, type: LocalExtensionType): TPromise<ILocalExtension> {
|
||||
const extensionPath = path.join(root, folderName);
|
||||
return pfs.readdir(extensionPath)
|
||||
.then(children => readManifest(extensionPath)
|
||||
.then<ILocalExtension>(({ manifest, metadata }) => {
|
||||
const readme = children.filter(child => /^readme(\.txt|\.md|)$/i.test(child))[0];
|
||||
const readmeUrl = readme ? URI.file(path.join(extensionPath, readme)).toString() : null;
|
||||
const changelog = children.filter(child => /^changelog(\.txt|\.md|)$/i.test(child))[0];
|
||||
const changelogUrl = changelog ? URI.file(path.join(extensionPath, changelog)).toString() : null;
|
||||
|
||||
return readManifest(extensionPath)
|
||||
.then<ILocalExtension>(({ manifest, metadata }) => {
|
||||
if (manifest.extensionDependencies) {
|
||||
manifest.extensionDependencies = manifest.extensionDependencies.map(id => adoptToGalleryExtensionId(id));
|
||||
}
|
||||
const identifier = { id, uuid: metadata ? metadata.id : null };
|
||||
return { type, identifier, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl };
|
||||
});
|
||||
}).then(null, () => null);
|
||||
|
||||
return limiter.queue(each);
|
||||
})))
|
||||
.then(result => result.filter(a => !!a));
|
||||
}
|
||||
|
||||
private scanExtensionFolders(root: string): TPromise<string[]> {
|
||||
return this.getObsoleteExtensions()
|
||||
.then(obsolete => pfs.readdir(root).then(extensions => extensions.filter(id => !obsolete[id])));
|
||||
if (manifest.extensionDependencies) {
|
||||
manifest.extensionDependencies = manifest.extensionDependencies.map(id => adoptToGalleryExtensionId(id));
|
||||
}
|
||||
const identifier = { id: type === LocalExtensionType.System ? folderName : getLocalExtensionIdFromManifest(manifest), uuid: metadata ? metadata.id : null };
|
||||
return { type, identifier, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl };
|
||||
}))
|
||||
.then(null, () => null);
|
||||
}
|
||||
|
||||
removeDeprecatedExtensions(): TPromise<any> {
|
||||
return TPromise.join([
|
||||
// Remove obsolte extensions first to avoid removing installed older extension. See #38609.
|
||||
this.removeObsoleteExtensions(),
|
||||
this.removeOutdatedExtensions()
|
||||
]);
|
||||
return this.removeUninstalledExtensions()
|
||||
.then(() => this.removeOutdatedExtensions());
|
||||
}
|
||||
|
||||
private removeOutdatedExtensions(): TPromise<any> {
|
||||
return this.getOutdatedExtensionIds()
|
||||
.then(extensionIds => this.removeExtensions(extensionIds));
|
||||
private removeUninstalledExtensions(): TPromise<void> {
|
||||
return this.getUninstalledExtensions()
|
||||
.then(uninstalled => this.scanExtensions(this.extensionsPath, LocalExtensionType.User) // All user extensions
|
||||
.then(extensions => {
|
||||
const toRemove: ILocalExtension[] = extensions.filter(e => uninstalled[e.identifier.id]);
|
||||
return TPromise.join(toRemove.map(e => this.extensionLifecycle.uninstall(e).then(() => this.removeUninstalledExtension(e))));
|
||||
})
|
||||
).then(() => null);
|
||||
}
|
||||
|
||||
private removeObsoleteExtensions(): TPromise<any> {
|
||||
return this.getObsoleteExtensions()
|
||||
.then(obsolete => Object.keys(obsolete))
|
||||
.then(extensionIds => this.removeExtensions(extensionIds));
|
||||
private removeOutdatedExtensions(): TPromise<void> {
|
||||
return this.scanExtensions(this.extensionsPath, LocalExtensionType.User) // All user extensions
|
||||
.then(extensions => {
|
||||
const toRemove: ILocalExtension[] = [];
|
||||
|
||||
// Outdated extensions
|
||||
const byExtension: ILocalExtension[][] = groupByExtension(extensions, e => ({ id: getGalleryExtensionIdFromLocal(e), uuid: e.identifier.uuid }));
|
||||
toRemove.push(...flatten(byExtension.map(p => p.sort((a, b) => semver.rcompare(a.manifest.version, b.manifest.version)).slice(1))));
|
||||
|
||||
return TPromise.join(toRemove.map(extension => this.removeExtension(extension, 'outdated')));
|
||||
}).then(() => null);
|
||||
}
|
||||
|
||||
private removeExtensions(extensionsIds: string[]): TPromise<any> {
|
||||
return TPromise.join(extensionsIds.map(id => {
|
||||
return pfs.rimraf(path.join(this.extensionsPath, id))
|
||||
.then(() => this.withObsoleteExtensions(obsolete => delete obsolete[id]));
|
||||
}));
|
||||
private removeUninstalledExtension(extension: ILocalExtension): TPromise<void> {
|
||||
return this.removeExtension(extension, 'uninstalled')
|
||||
.then(() => this.withUninstalledExtensions(uninstalled => delete uninstalled[extension.identifier.id]))
|
||||
.then(() => null);
|
||||
}
|
||||
|
||||
private getOutdatedExtensionIds(): TPromise<string[]> {
|
||||
return this.scanExtensionFolders(this.extensionsPath)
|
||||
.then(folders => {
|
||||
const galleryFolders = folders
|
||||
.map(folder => (assign({ folder }, getIdAndVersionFromLocalExtensionId(folder))))
|
||||
.filter(({ id, version }) => !!id && !!version);
|
||||
|
||||
const byId = values(groupBy(galleryFolders, p => p.id));
|
||||
|
||||
return flatten(byId.map(p => p.sort((a, b) => semver.rcompare(a.version, b.version)).slice(1)))
|
||||
.map(a => a.folder);
|
||||
});
|
||||
private removeExtension(extension: ILocalExtension, type: string): TPromise<void> {
|
||||
this.logService.trace(`Deleting ${type} extension from disk`, extension.identifier.id);
|
||||
return pfs.rimraf(extension.path).then(() => this.logService.info('Deleted from disk', extension.identifier.id));
|
||||
}
|
||||
|
||||
private isObsolete(id: string): TPromise<boolean> {
|
||||
return this.filterObsolete(id).then(obsolete => obsolete.length === 1);
|
||||
private isUninstalled(id: string): TPromise<boolean> {
|
||||
return this.filterUninstalled(id).then(uninstalled => uninstalled.length === 1);
|
||||
}
|
||||
|
||||
private filterObsolete(...ids: string[]): TPromise<string[]> {
|
||||
return this.withObsoleteExtensions(allObsolete => {
|
||||
const obsolete = [];
|
||||
private filterUninstalled(...ids: string[]): TPromise<string[]> {
|
||||
return this.withUninstalledExtensions(allUninstalled => {
|
||||
const uninstalled = [];
|
||||
for (const id of ids) {
|
||||
if (!!allObsolete[id]) {
|
||||
obsolete.push(id);
|
||||
if (!!allUninstalled[id]) {
|
||||
uninstalled.push(id);
|
||||
}
|
||||
}
|
||||
return obsolete;
|
||||
return uninstalled;
|
||||
});
|
||||
}
|
||||
|
||||
private setObsolete(id: string): TPromise<void> {
|
||||
return this.withObsoleteExtensions(obsolete => assign(obsolete, { [id]: true }));
|
||||
private setUninstalled(...ids: string[]): TPromise<void> {
|
||||
return this.withUninstalledExtensions(uninstalled => assign(uninstalled, ids.reduce((result, id) => { result[id] = true; return result; }, {})));
|
||||
}
|
||||
|
||||
private unsetObsolete(id: string): TPromise<void> {
|
||||
return this.withObsoleteExtensions<void>(obsolete => delete obsolete[id]);
|
||||
private unsetUninstalled(id: string): TPromise<void> {
|
||||
return this.withUninstalledExtensions<void>(uninstalled => delete uninstalled[id]);
|
||||
}
|
||||
|
||||
private getObsoleteExtensions(): TPromise<{ [id: string]: boolean; }> {
|
||||
return this.withObsoleteExtensions(obsolete => obsolete);
|
||||
private getUninstalledExtensions(): TPromise<{ [id: string]: boolean; }> {
|
||||
return this.withUninstalledExtensions(uninstalled => uninstalled);
|
||||
}
|
||||
|
||||
private withObsoleteExtensions<T>(fn: (obsolete: { [id: string]: boolean; }) => T): TPromise<T> {
|
||||
return this.obsoleteFileLimiter.queue(() => {
|
||||
private withUninstalledExtensions<T>(fn: (uninstalled: { [id: string]: boolean; }) => T): TPromise<T> {
|
||||
return this.uninstalledFileLimiter.queue(() => {
|
||||
let result: T = null;
|
||||
return pfs.readFile(this.obsoletePath, 'utf8')
|
||||
return pfs.readFile(this.uninstalledPath, 'utf8')
|
||||
.then(null, err => err.code === 'ENOENT' ? TPromise.as('{}') : TPromise.wrapError(err))
|
||||
.then<{ [id: string]: boolean }>(raw => { try { return JSON.parse(raw); } catch (e) { return {}; } })
|
||||
.then(obsolete => { result = fn(obsolete); return obsolete; })
|
||||
.then(obsolete => {
|
||||
if (Object.keys(obsolete).length === 0) {
|
||||
return pfs.rimraf(this.obsoletePath);
|
||||
.then(uninstalled => { result = fn(uninstalled); return uninstalled; })
|
||||
.then(uninstalled => {
|
||||
if (Object.keys(uninstalled).length === 0) {
|
||||
return pfs.rimraf(this.uninstalledPath);
|
||||
} else {
|
||||
const raw = JSON.stringify(obsolete);
|
||||
return pfs.writeFile(this.obsoletePath, raw);
|
||||
const raw = JSON.stringify(uninstalled);
|
||||
return pfs.writeFile(this.uninstalledPath, raw);
|
||||
}
|
||||
})
|
||||
.then(() => result);
|
||||
@@ -774,10 +852,6 @@ export class ExtensionManagementService implements IExtensionManagementService {
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.disposables = dispose(this.disposables);
|
||||
}
|
||||
}
|
||||
|
||||
export function getLocalExtensionIdFromGallery(extension: IGalleryExtension, version: string): string {
|
||||
@@ -786,8 +860,4 @@ export function getLocalExtensionIdFromGallery(extension: IGalleryExtension, ver
|
||||
|
||||
export function getLocalExtensionIdFromManifest(manifest: IExtensionManifest): string {
|
||||
return getLocalExtensionId(getGalleryExtensionId(manifest.publisher, manifest.name), manifest.version);
|
||||
}
|
||||
|
||||
function getLocalExtensionId(id: string, version: string): string {
|
||||
return `${id}-${version}`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user