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