Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/extensionManagement/node/extensionsManifestCache.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Disposable } from '../../../base/common/lifecycle.js';
7
import { URI } from '../../../base/common/uri.js';
8
import { DidUninstallExtensionEvent, IExtensionManagementService, InstallExtensionResult } from '../common/extensionManagement.js';
9
import { USER_MANIFEST_CACHE_FILE } from '../../extensions/common/extensions.js';
10
import { FileOperationResult, IFileService, toFileOperationResult } from '../../files/common/files.js';
11
import { ILogService } from '../../log/common/log.js';
12
import { IUriIdentityService } from '../../uriIdentity/common/uriIdentity.js';
13
import { IUserDataProfile, IUserDataProfilesService } from '../../userDataProfile/common/userDataProfile.js';
14
15
export class ExtensionsManifestCache extends Disposable {
16
17
constructor(
18
private readonly userDataProfilesService: IUserDataProfilesService,
19
private readonly fileService: IFileService,
20
private readonly uriIdentityService: IUriIdentityService,
21
extensionsManagementService: IExtensionManagementService,
22
private readonly logService: ILogService,
23
) {
24
super();
25
this._register(extensionsManagementService.onDidInstallExtensions(e => this.onDidInstallExtensions(e)));
26
this._register(extensionsManagementService.onDidUninstallExtension(e => this.onDidUnInstallExtension(e)));
27
}
28
29
private onDidInstallExtensions(results: readonly InstallExtensionResult[]): void {
30
for (const r of results) {
31
if (r.local) {
32
this.invalidate(r.profileLocation);
33
}
34
}
35
}
36
37
private onDidUnInstallExtension(e: DidUninstallExtensionEvent): void {
38
if (!e.error) {
39
this.invalidate(e.profileLocation);
40
}
41
}
42
43
async invalidate(extensionsManifestLocation: URI | undefined): Promise<void> {
44
if (extensionsManifestLocation) {
45
for (const profile of this.userDataProfilesService.profiles) {
46
if (this.uriIdentityService.extUri.isEqual(profile.extensionsResource, extensionsManifestLocation)) {
47
await this.deleteUserCacheFile(profile);
48
}
49
}
50
} else {
51
await this.deleteUserCacheFile(this.userDataProfilesService.defaultProfile);
52
}
53
}
54
55
private async deleteUserCacheFile(profile: IUserDataProfile): Promise<void> {
56
try {
57
await this.fileService.del(this.uriIdentityService.extUri.joinPath(profile.cacheHome, USER_MANIFEST_CACHE_FILE));
58
} catch (error) {
59
if (toFileOperationResult(error) !== FileOperationResult.FILE_NOT_FOUND) {
60
this.logService.error(error);
61
}
62
}
63
}
64
}
65
66