@@ -18,12 +18,10 @@ import {
18
18
ServerInstallOptions , ServerInstallVSIXOptions , ServerUninstallOptions , Metadata , ServerInstallExtensionEvent , ServerInstallExtensionResult , ServerUninstallExtensionEvent , ServerDidUninstallExtensionEvent
19
19
} from 'vs/platform/extensionManagement/common/extensionManagement' ;
20
20
import { areSameExtensions , ExtensionKey , getGalleryExtensionTelemetryData , getLocalExtensionTelemetryData , getMaliciousExtensionsSet } from 'vs/platform/extensionManagement/common/extensionManagementUtil' ;
21
- import { IExtensionsProfileScannerService } from 'vs/platform/extensionManagement/common/extensionsProfileScannerService' ;
22
- import { ExtensionType , IExtensionManifest , TargetPlatform } from 'vs/platform/extensions/common/extensions' ;
21
+ import { ExtensionType , IExtensionManifest , isApplicationScopedExtension , TargetPlatform } from 'vs/platform/extensions/common/extensions' ;
23
22
import { ILogService } from 'vs/platform/log/common/log' ;
24
23
import { IProductService } from 'vs/platform/product/common/productService' ;
25
24
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
26
- import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity' ;
27
25
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile' ;
28
26
29
27
export interface IInstallExtensionTask {
@@ -66,13 +64,11 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
66
64
private readonly participants : IExtensionManagementParticipant [ ] = [ ] ;
67
65
68
66
constructor (
69
- @IUserDataProfilesService private readonly userDataProfilesService : IUserDataProfilesService ,
70
- @IUriIdentityService private readonly uriIdenityService : IUriIdentityService ,
71
67
@IExtensionGalleryService protected readonly galleryService : IExtensionGalleryService ,
72
- @IExtensionsProfileScannerService protected readonly extensionsProfileScannerService : IExtensionsProfileScannerService ,
73
68
@ITelemetryService protected readonly telemetryService : ITelemetryService ,
74
69
@ILogService protected readonly logService : ILogService ,
75
- @IProductService protected readonly productService : IProductService
70
+ @IProductService protected readonly productService : IProductService ,
71
+ @IUserDataProfilesService protected readonly userDataProfilesService : IUserDataProfilesService ,
76
72
) {
77
73
super ( ) ;
78
74
this . _register ( toDisposable ( ( ) => {
@@ -120,7 +116,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
120
116
throw new Error ( nls . localize ( 'Not a Marketplace extension' , "Only Marketplace Extensions can be reinstalled" ) ) ;
121
117
}
122
118
123
- await this . createDefaultUninstallExtensionTask ( extension , { remove : true , versionOnly : true } ) . run ( ) ;
119
+ await this . createUninstallExtensionTask ( extension , { remove : true , versionOnly : true } ) . run ( ) ;
124
120
await this . installFromGallery ( galleryExtension ) ;
125
121
}
126
122
@@ -140,13 +136,15 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
140
136
}
141
137
142
138
protected async installExtension ( manifest : IExtensionManifest , extension : URI | IGalleryExtension , options : ServerInstallOptions & ServerInstallVSIXOptions ) : Promise < ILocalExtension > {
139
+
140
+ const getInstallExtensionTaskKey = ( extension : IGalleryExtension ) => `${ ExtensionKey . create ( extension ) . toString ( ) } ${ options . profileLocation ? `-${ options . profileLocation . toString ( ) } ` : '' } ` ;
141
+
143
142
// only cache gallery extensions tasks
144
143
if ( ! URI . isUri ( extension ) ) {
145
- const installExtensionTask = this . installingExtensions . get ( ExtensionKey . create ( extension ) . toString ( ) ) ;
144
+ const installExtensionTask = this . installingExtensions . get ( getInstallExtensionTaskKey ( extension ) ) ;
146
145
if ( installExtensionTask ) {
147
146
this . logService . info ( 'Extensions is already requested to install' , extension . identifier . id ) ;
148
- const waitUntilTaskIsFinishedTask = this . createWaitUntilInstallExtensionTaskIsFinishedTask ( installExtensionTask , options ) ;
149
- const { local } = await waitUntilTaskIsFinishedTask . waitUntilTaskIsFinished ( ) ;
147
+ const { local } = await installExtensionTask . waitUntilTaskIsFinished ( ) ;
150
148
return local ;
151
149
}
152
150
options = { ...options , installOnlyNewlyAddedFromExtensionPack : true /* always true for gallery extensions */ } ;
@@ -156,7 +154,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
156
154
const installResults : ( ServerInstallExtensionResult & { local : ILocalExtension } ) [ ] = [ ] ;
157
155
const installExtensionTask = this . createInstallExtensionTask ( manifest , extension , options ) ;
158
156
if ( ! URI . isUri ( extension ) ) {
159
- this . installingExtensions . set ( ExtensionKey . create ( extension ) . toString ( ) , installExtensionTask ) ;
157
+ this . installingExtensions . set ( getInstallExtensionTaskKey ( extension ) , installExtensionTask ) ;
160
158
}
161
159
this . _onInstallExtension . fire ( { identifier : installExtensionTask . identifier , source : extension , profileLocation : options . profileLocation } ) ;
162
160
this . logService . info ( 'Installing extension:' , installExtensionTask . identifier . id ) ;
@@ -171,7 +169,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
171
169
const allDepsAndPackExtensionsToInstall = await this . getAllDepsAndPackExtensionsToInstall ( installExtensionTask . identifier , manifest , ! ! options . installOnlyNewlyAddedFromExtensionPack , ! ! options . installPreReleaseVersion , options . profileLocation ) ;
172
170
for ( const { gallery, manifest } of allDepsAndPackExtensionsToInstall ) {
173
171
installExtensionHasDependents = installExtensionHasDependents || ! ! manifest . extensionDependencies ?. some ( id => areSameExtensions ( { id } , installExtensionTask . identifier ) ) ;
174
- const key = ExtensionKey . create ( gallery ) . toString ( ) ;
172
+ const key = getInstallExtensionTaskKey ( gallery ) ;
175
173
if ( this . installingExtensions . has ( key ) ) {
176
174
this . logService . info ( 'Extension is already requested to install' , gallery . identifier . id ) ;
177
175
} else {
@@ -260,7 +258,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
260
258
// rollback installed extensions
261
259
if ( installResults . length ) {
262
260
try {
263
- const result = await Promise . allSettled ( installResults . map ( ( { local } ) => this . createUninstallExtensionTask ( local , { versionOnly : true } , options . profileLocation ) . run ( ) ) ) ;
261
+ const result = await Promise . allSettled ( installResults . map ( ( { local } ) => this . createUninstallExtensionTask ( local , { versionOnly : true , profileLocation : options . profileLocation } ) . run ( ) ) ) ;
264
262
for ( let index = 0 ; index < result . length ; index ++ ) {
265
263
const r = result [ index ] ;
266
264
const { identifier } = installResults [ index ] ;
@@ -282,7 +280,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
282
280
/* Remove the gallery tasks from the cache */
283
281
for ( const { task } of allInstallExtensionTasks ) {
284
282
if ( ! URI . isUri ( task . source ) ) {
285
- const key = ExtensionKey . create ( task . source ) . toString ( ) ;
283
+ const key = getInstallExtensionTaskKey ( task . source ) ;
286
284
if ( ! this . installingExtensions . delete ( key ) ) {
287
285
this . logService . warn ( 'Installation task is not found in the cache' , key ) ;
288
286
}
@@ -434,7 +432,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
434
432
}
435
433
436
434
const createUninstallExtensionTask = ( extension : ILocalExtension , uninstallOptions : ServerUninstallOptions ) : IUninstallExtensionTask => {
437
- const uninstallExtensionTask = this . createUninstallExtensionTask ( extension , uninstallOptions , options . profileLocation ) ;
435
+ const uninstallExtensionTask = this . createUninstallExtensionTask ( extension , uninstallOptions ) ;
438
436
this . uninstallingExtensions . set ( getUninstallExtensionTaskKey ( uninstallExtensionTask . extension . identifier ) , uninstallExtensionTask ) ;
439
437
if ( options . profileLocation ) {
440
438
this . logService . info ( 'Uninstalling extension from the profile:' , `${ extension . identifier . id } @${ extension . manifest . version } ` , options . profileLocation . toString ( ) ) ;
@@ -604,22 +602,17 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
604
602
}
605
603
606
604
private createInstallExtensionTask ( manifest : IExtensionManifest , extension : URI | IGalleryExtension , options : ServerInstallOptions & ServerInstallVSIXOptions ) : IInstallExtensionTask {
607
- const installTask = this . createDefaultInstallExtensionTask ( manifest , extension , options ) ;
608
- return options . profileLocation && this . userDataProfilesService . defaultProfile . extensionsResource ? new InstallExtensionInProfileTask ( installTask , options . profileLocation , this . userDataProfilesService . defaultProfile . extensionsResource , this . extensionsProfileScannerService ) : installTask ;
609
- }
610
-
611
- private createWaitUntilInstallExtensionTaskIsFinishedTask ( installTask : IInstallExtensionTask , options : ServerInstallOptions & ServerInstallVSIXOptions ) : IInstallExtensionTask {
612
- if ( ! options . profileLocation || ! this . userDataProfilesService . defaultProfile . extensionsResource ) {
613
- return installTask ;
614
- }
615
- if ( installTask instanceof InstallExtensionInProfileTask && this . uriIdenityService . extUri . isEqual ( installTask . profileLocation , options . profileLocation ) ) {
616
- return installTask ;
605
+ if ( options . profileLocation && isApplicationScopedExtension ( manifest ) ) {
606
+ options = { ...options , profileLocation : this . userDataProfilesService . defaultProfile . extensionsResource } ;
617
607
}
618
- return new InstallExtensionInProfileTask ( installTask , options . profileLocation , this . userDataProfilesService . defaultProfile . extensionsResource , this . extensionsProfileScannerService ) ;
608
+ return this . doCreateInstallExtensionTask ( manifest , extension , options ) ;
619
609
}
620
610
621
- private createUninstallExtensionTask ( extension : ILocalExtension , options : ServerUninstallOptions , profile ?: URI ) : IUninstallExtensionTask {
622
- return profile && this . userDataProfilesService . defaultProfile . extensionsResource ? new UninstallExtensionFromProfileTask ( extension , profile , this . userDataProfilesService , this . extensionsProfileScannerService ) : this . createDefaultUninstallExtensionTask ( extension , options ) ;
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 ) ;
623
616
}
624
617
625
618
abstract getTargetPlatform ( ) : Promise < TargetPlatform > ;
@@ -633,8 +626,8 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
633
626
abstract updateMetadata ( local : ILocalExtension , metadata : IGalleryMetadata ) : Promise < ILocalExtension > ;
634
627
abstract updateExtensionScope ( local : ILocalExtension , isMachineScoped : boolean ) : Promise < ILocalExtension > ;
635
628
636
- protected abstract createDefaultInstallExtensionTask ( manifest : IExtensionManifest , extension : URI | IGalleryExtension , options : ServerInstallOptions & ServerInstallVSIXOptions ) : IInstallExtensionTask ;
637
- protected abstract createDefaultUninstallExtensionTask ( 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 ;
638
631
}
639
632
640
633
export function joinErrors ( errorOrErrors : ( Error | string ) | ( Array < Error | string > ) ) : Error {
@@ -731,63 +724,3 @@ export abstract class AbstractExtensionTask<T> {
731
724
732
725
protected abstract doRun ( token : CancellationToken ) : Promise < T > ;
733
726
}
734
-
735
- class InstallExtensionInProfileTask implements IInstallExtensionTask {
736
-
737
- readonly identifier = this . task . identifier ;
738
- readonly source = this . task . source ;
739
- readonly operation = this . task . operation ;
740
-
741
- private readonly promise : Promise < { local : ILocalExtension ; metadata : Metadata } > ;
742
-
743
- constructor (
744
- private readonly task : IInstallExtensionTask ,
745
- readonly profileLocation : URI ,
746
- private readonly defaultProfileLocation : URI ,
747
- private readonly extensionsProfileScannerService : IExtensionsProfileScannerService ,
748
- ) {
749
- this . promise = this . waitAndAddExtensionToProfile ( ) ;
750
- }
751
-
752
- private async waitAndAddExtensionToProfile ( ) : Promise < { local : ILocalExtension ; metadata : Metadata } > {
753
- const result = await this . task . waitUntilTaskIsFinished ( ) ;
754
- const profileLocation = result . local . isApplicationScoped ? this . defaultProfileLocation : this . profileLocation ;
755
- await this . extensionsProfileScannerService . addExtensionsToProfile ( [ [ result . local , result . metadata ] ] , profileLocation ) ;
756
- return result ;
757
- }
758
-
759
- async run ( ) : Promise < { local : ILocalExtension ; metadata : Metadata } > {
760
- await this . task . run ( ) ;
761
- return this . promise ;
762
- }
763
-
764
- waitUntilTaskIsFinished ( ) : Promise < { local : ILocalExtension ; metadata : Metadata } > {
765
- return this . promise ;
766
- }
767
-
768
- cancel ( ) : void {
769
- return this . task . cancel ( ) ;
770
- }
771
- }
772
-
773
- class UninstallExtensionFromProfileTask extends AbstractExtensionTask < void > implements IUninstallExtensionTask {
774
-
775
- constructor (
776
- readonly extension : ILocalExtension ,
777
- private readonly profileLocation : URI ,
778
- private readonly userDataProfilesService : IUserDataProfilesService ,
779
- private readonly extensionsProfileScannerService : IExtensionsProfileScannerService ,
780
- ) {
781
- super ( ) ;
782
- }
783
-
784
- protected async doRun ( token : CancellationToken ) : Promise < void > {
785
- const promises : Promise < any > [ ] = [ ] ;
786
- promises . push ( this . extensionsProfileScannerService . removeExtensionFromProfile ( this . extension . identifier , this . profileLocation ) ) ;
787
- if ( this . extension . isApplicationScoped && this . userDataProfilesService . defaultProfile . extensionsResource ) {
788
- promises . push ( this . extensionsProfileScannerService . removeExtensionFromProfile ( this . extension . identifier , this . userDataProfilesService . defaultProfile . extensionsResource ) ) ;
789
- }
790
- await Promise . all ( promises ) ;
791
- }
792
-
793
- }
0 commit comments