Skip to content

Commit d4447ae

Browse files
committed
check application scope in abstract layer
1 parent 61a9d72 commit d4447ae

File tree

3 files changed

+33
-25
lines changed

3 files changed

+33
-25
lines changed

src/vs/platform/extensionManagement/common/abstractExtensionManagementService.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ import {
1818
ServerInstallOptions, ServerInstallVSIXOptions, ServerUninstallOptions, Metadata, ServerInstallExtensionEvent, ServerInstallExtensionResult, ServerUninstallExtensionEvent, ServerDidUninstallExtensionEvent
1919
} from 'vs/platform/extensionManagement/common/extensionManagement';
2020
import { areSameExtensions, ExtensionKey, getGalleryExtensionTelemetryData, getLocalExtensionTelemetryData, getMaliciousExtensionsSet } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
21-
import { ExtensionType, IExtensionManifest, TargetPlatform } from 'vs/platform/extensions/common/extensions';
21+
import { ExtensionType, IExtensionManifest, isApplicationScopedExtension, TargetPlatform } from 'vs/platform/extensions/common/extensions';
2222
import { ILogService } from 'vs/platform/log/common/log';
2323
import { IProductService } from 'vs/platform/product/common/productService';
2424
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
25+
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
2526

2627
export interface IInstallExtensionTask {
2728
readonly identifier: IExtensionIdentifier;
@@ -66,7 +67,8 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
6667
@IExtensionGalleryService protected readonly galleryService: IExtensionGalleryService,
6768
@ITelemetryService protected readonly telemetryService: ITelemetryService,
6869
@ILogService protected readonly logService: ILogService,
69-
@IProductService protected readonly productService: IProductService
70+
@IProductService protected readonly productService: IProductService,
71+
@IUserDataProfilesService protected readonly userDataProfilesService: IUserDataProfilesService,
7072
) {
7173
super();
7274
this._register(toDisposable(() => {
@@ -599,6 +601,20 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
599601
}
600602
}
601603

604+
private createInstallExtensionTask(manifest: IExtensionManifest, extension: URI | IGalleryExtension, options: ServerInstallOptions & ServerInstallVSIXOptions): IInstallExtensionTask {
605+
if (options.profileLocation && isApplicationScopedExtension(manifest)) {
606+
options = { ...options, profileLocation: this.userDataProfilesService.defaultProfile.extensionsResource };
607+
}
608+
return this.doCreateInstallExtensionTask(manifest, extension, options);
609+
}
610+
611+
private createUninstallExtensionTask(extension: ILocalExtension, options: ServerUninstallOptions): IUninstallExtensionTask {
612+
if (options.profileLocation && extension.isApplicationScoped) {
613+
options = { ...options, profileLocation: this.userDataProfilesService.defaultProfile.extensionsResource };
614+
}
615+
return this.doCreateUninstallExtensionTask(extension, options);
616+
}
617+
602618
abstract getTargetPlatform(): Promise<TargetPlatform>;
603619
abstract zip(extension: ILocalExtension): Promise<URI>;
604620
abstract unzip(zipLocation: URI): Promise<IExtensionIdentifier>;
@@ -610,8 +626,8 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
610626
abstract updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): Promise<ILocalExtension>;
611627
abstract updateExtensionScope(local: ILocalExtension, isMachineScoped: boolean): Promise<ILocalExtension>;
612628

613-
protected abstract createInstallExtensionTask(manifest: IExtensionManifest, extension: URI | IGalleryExtension, options: ServerInstallOptions & ServerInstallVSIXOptions): IInstallExtensionTask;
614-
protected abstract createUninstallExtensionTask(extension: ILocalExtension, options: ServerUninstallOptions): IUninstallExtensionTask;
629+
protected abstract doCreateInstallExtensionTask(manifest: IExtensionManifest, extension: URI | IGalleryExtension, options: ServerInstallOptions & ServerInstallVSIXOptions): IInstallExtensionTask;
630+
protected abstract doCreateUninstallExtensionTask(extension: ILocalExtension, options: ServerUninstallOptions): IUninstallExtensionTask;
615631
}
616632

617633
export function joinErrors(errorOrErrors: (Error | string) | (Array<Error | string>)): Error {

src/vs/platform/extensionManagement/node/extensionManagementService.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ export class ExtensionManagementService extends AbstractExtensionManagementServi
7979
@IFileService private readonly fileService: IFileService,
8080
@IProductService productService: IProductService,
8181
@IUriIdentityService uriIdentityService: IUriIdentityService,
82-
@IUserDataProfilesService private readonly userDataProfilesService: IUserDataProfilesService,
82+
@IUserDataProfilesService userDataProfilesService: IUserDataProfilesService,
8383
) {
84-
super(galleryService, telemetryService, logService, productService);
84+
super(galleryService, telemetryService, logService, productService, userDataProfilesService);
8585
const extensionLifecycle = this._register(instantiationService.createInstance(ExtensionsLifecycle));
8686
this.extensionsScanner = this._register(instantiationService.createInstance(ExtensionsScanner, extension => extensionLifecycle.postUninstall(extension)));
8787
this.manifestCache = this._register(new ExtensionsManifestCache(environmentService, this));
@@ -178,7 +178,7 @@ export class ExtensionManagementService extends AbstractExtensionManagementServi
178178
return downloadedLocation;
179179
}
180180

181-
protected createInstallExtensionTask(manifest: IExtensionManifest, extension: URI | IGalleryExtension, options: ServerInstallOptions & ServerInstallVSIXOptions): IInstallExtensionTask {
181+
protected doCreateInstallExtensionTask(manifest: IExtensionManifest, extension: URI | IGalleryExtension, options: ServerInstallOptions & ServerInstallVSIXOptions): IInstallExtensionTask {
182182
let installExtensionTask: IInstallExtensionTask | undefined;
183183
if (URI.isUri(extension)) {
184184
installExtensionTask = new InstallVSIXTask(manifest, extension, options, this.galleryService, this.extensionsScanner, this.logService);
@@ -190,15 +190,15 @@ export class ExtensionManagementService extends AbstractExtensionManagementServi
190190
installExtensionTask.waitUntilTaskIsFinished().then(() => this.installGalleryExtensionsTasks.delete(key));
191191
}
192192
}
193-
if (options.profileLocation && this.userDataProfilesService.defaultProfile.extensionsResource) {
194-
return new InstallExtensionInProfileTask(installExtensionTask, options.profileLocation, this.userDataProfilesService.defaultProfile.extensionsResource, this.extensionsProfileScannerService);
193+
if (options.profileLocation) {
194+
return new InstallExtensionInProfileTask(installExtensionTask, options.profileLocation, this.extensionsProfileScannerService);
195195
}
196196
return installExtensionTask;
197197
}
198198

199-
protected createUninstallExtensionTask(extension: ILocalExtension, options: ServerUninstallOptions): IUninstallExtensionTask {
200-
if (options.profileLocation && this.userDataProfilesService.defaultProfile.extensionsResource) {
201-
return new UninstallExtensionFromProfileTask(extension, options.profileLocation, this.userDataProfilesService, this.extensionsProfileScannerService);
199+
protected doCreateUninstallExtensionTask(extension: ILocalExtension, options: ServerUninstallOptions): IUninstallExtensionTask {
200+
if (options.profileLocation) {
201+
return new UninstallExtensionFromProfileTask(extension, options.profileLocation, this.extensionsProfileScannerService);
202202
}
203203
return new UninstallExtensionTask(extension, options, this.extensionsScanner);
204204
}
@@ -735,17 +735,15 @@ class InstallExtensionInProfileTask implements IInstallExtensionTask {
735735

736736
constructor(
737737
private readonly task: IInstallExtensionTask,
738-
readonly profileLocation: URI,
739-
private readonly defaultProfileLocation: URI,
738+
private readonly profileLocation: URI,
740739
private readonly extensionsProfileScannerService: IExtensionsProfileScannerService,
741740
) {
742741
this.promise = this.waitAndAddExtensionToProfile();
743742
}
744743

745744
private async waitAndAddExtensionToProfile(): Promise<{ local: ILocalExtension; metadata: Metadata }> {
746745
const result = await this.task.waitUntilTaskIsFinished();
747-
const profileLocation = result.local.isApplicationScoped ? this.defaultProfileLocation : this.profileLocation;
748-
await this.extensionsProfileScannerService.addExtensionsToProfile([[result.local, result.metadata]], profileLocation);
746+
await this.extensionsProfileScannerService.addExtensionsToProfile([[result.local, result.metadata]], this.profileLocation);
749747
return result;
750748
}
751749

@@ -808,19 +806,13 @@ class UninstallExtensionFromProfileTask extends AbstractExtensionTask<void> impl
808806
constructor(
809807
readonly extension: ILocalExtension,
810808
private readonly profileLocation: URI,
811-
private readonly userDataProfilesService: IUserDataProfilesService,
812809
private readonly extensionsProfileScannerService: IExtensionsProfileScannerService,
813810
) {
814811
super();
815812
}
816813

817814
protected async doRun(token: CancellationToken): Promise<void> {
818-
const promises: Promise<any>[] = [];
819-
promises.push(this.extensionsProfileScannerService.removeExtensionFromProfile(this.extension.identifier, this.profileLocation));
820-
if (this.extension.isApplicationScoped && this.userDataProfilesService.defaultProfile.extensionsResource) {
821-
promises.push(this.extensionsProfileScannerService.removeExtensionFromProfile(this.extension.identifier, this.userDataProfilesService.defaultProfile.extensionsResource));
822-
}
823-
await Promise.all(promises);
815+
await this.extensionsProfileScannerService.removeExtensionFromProfile(this.extension.identifier, this.profileLocation);
824816
}
825817

826818
}

src/vs/workbench/services/extensionManagement/common/webExtensionManagementService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ export class WebExtensionManagementService extends AbstractExtensionManagementSe
9595
return local;
9696
}
9797

98-
protected createInstallExtensionTask(manifest: IExtensionManifest, extension: URI | IGalleryExtension, options: InstallOptions): IInstallExtensionTask {
98+
protected doCreateInstallExtensionTask(manifest: IExtensionManifest, extension: URI | IGalleryExtension, options: InstallOptions): IInstallExtensionTask {
9999
return new InstallExtensionTask(manifest, extension, options, this.webExtensionsScannerService);
100100
}
101101

102-
protected createUninstallExtensionTask(extension: ILocalExtension, options: UninstallOptions): IUninstallExtensionTask {
102+
protected doCreateUninstallExtensionTask(extension: ILocalExtension, options: UninstallOptions): IUninstallExtensionTask {
103103
return new UninstallExtensionTask(extension, options, this.webExtensionsScannerService);
104104
}
105105

0 commit comments

Comments
 (0)