Skip to content

Commit 625bae2

Browse files
authored
debt: clean up obsolete file usage (microsoft#236379)
- remove it from scanner, with profiles reading this file is not needed - rename it usage for removal in management service
1 parent dfa26a2 commit 625bae2

File tree

5 files changed

+115
-156
lines changed

5 files changed

+115
-156
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ export const enum ExtensionManagementErrorCode {
456456
Extract = 'Extract',
457457
Scanning = 'Scanning',
458458
ScanningExtension = 'ScanningExtension',
459-
ReadUninstalled = 'ReadUninstalled',
460-
UnsetUninstalled = 'UnsetUninstalled',
459+
ReadRemoved = 'ReadRemoved',
460+
UnsetRemoved = 'UnsetRemoved',
461461
Delete = 'Delete',
462462
Rename = 'Rename',
463463
IntializeDefaultProfile = 'IntializeDefaultProfile',

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

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { coalesce } from '../../../base/common/arrays.js';
77
import { ThrottledDelayer } from '../../../base/common/async.js';
88
import * as objects from '../../../base/common/objects.js';
99
import { VSBuffer } from '../../../base/common/buffer.js';
10-
import { IStringDictionary } from '../../../base/common/collections.js';
1110
import { getErrorMessage } from '../../../base/common/errors.js';
1211
import { getNodeType, parse, ParseError } from '../../../base/common/json.js';
1312
import { getParseErrorMessage } from '../../../base/common/jsonErrorMessages.js';
@@ -18,12 +17,11 @@ import * as platform from '../../../base/common/platform.js';
1817
import { basename, isEqual, joinPath } from '../../../base/common/resources.js';
1918
import * as semver from '../../../base/common/semver/semver.js';
2019
import Severity from '../../../base/common/severity.js';
21-
import { isEmptyObject } from '../../../base/common/types.js';
2220
import { URI } from '../../../base/common/uri.js';
2321
import { localize } from '../../../nls.js';
2422
import { IEnvironmentService } from '../../environment/common/environment.js';
2523
import { IProductVersion, Metadata } from './extensionManagement.js';
26-
import { areSameExtensions, computeTargetPlatform, ExtensionKey, getExtensionId, getGalleryExtensionId } from './extensionManagementUtil.js';
24+
import { areSameExtensions, computeTargetPlatform, getExtensionId, getGalleryExtensionId } from './extensionManagementUtil.js';
2725
import { ExtensionType, ExtensionIdentifier, IExtensionManifest, TargetPlatform, IExtensionIdentifier, IRelaxedExtensionManifest, UNDEFINED_PUBLISHER, IExtensionDescription, BUILTIN_MANIFEST_CACHE_FILE, USER_MANIFEST_CACHE_FILE, ExtensionIdentifierMap, parseEnabledApiProposalNames } from '../../extensions/common/extensions.js';
2826
import { validateExtensionManifest } from '../../extensions/common/extensionValidator.js';
2927
import { FileOperationResult, IFileService, toFileOperationResult } from '../../files/common/files.js';
@@ -106,7 +104,6 @@ export type ScanOptions = {
106104
readonly profileLocation?: URI;
107105
readonly includeInvalid?: boolean;
108106
readonly includeAllVersions?: boolean;
109-
readonly includeUninstalled?: boolean;
110107
readonly checkControlFile?: boolean;
111108
readonly language?: string;
112109
readonly useCache?: boolean;
@@ -145,10 +142,9 @@ export abstract class AbstractExtensionsScannerService extends Disposable implem
145142
private readonly _onDidChangeCache = this._register(new Emitter<ExtensionType>());
146143
readonly onDidChangeCache = this._onDidChangeCache.event;
147144

148-
private readonly obsoleteFile = joinPath(this.userExtensionsLocation, '.obsolete');
149-
private readonly systemExtensionsCachedScanner = this._register(this.instantiationService.createInstance(CachedExtensionsScanner, this.currentProfile, this.obsoleteFile));
150-
private readonly userExtensionsCachedScanner = this._register(this.instantiationService.createInstance(CachedExtensionsScanner, this.currentProfile, this.obsoleteFile));
151-
private readonly extensionsScanner = this._register(this.instantiationService.createInstance(ExtensionsScanner, this.obsoleteFile));
145+
private readonly systemExtensionsCachedScanner = this._register(this.instantiationService.createInstance(CachedExtensionsScanner, this.currentProfile));
146+
private readonly userExtensionsCachedScanner = this._register(this.instantiationService.createInstance(CachedExtensionsScanner, this.currentProfile));
147+
private readonly extensionsScanner = this._register(this.instantiationService.createInstance(ExtensionsScanner));
152148

153149
constructor(
154150
readonly systemExtensionsLocation: URI,
@@ -199,8 +195,8 @@ export abstract class AbstractExtensionsScannerService extends Disposable implem
199195
const location = scanOptions.profileLocation ?? this.userExtensionsLocation;
200196
this.logService.trace('Started scanning user extensions', location);
201197
const profileScanOptions: IProfileExtensionsScanOptions | undefined = this.uriIdentityService.extUri.isEqual(scanOptions.profileLocation, this.userDataProfilesService.defaultProfile.extensionsResource) ? { bailOutWhenFileNotFound: true } : undefined;
202-
const extensionsScannerInput = await this.createExtensionScannerInput(location, !!scanOptions.profileLocation, ExtensionType.User, !scanOptions.includeUninstalled, scanOptions.language, true, profileScanOptions, scanOptions.productVersion ?? this.getProductVersion());
203-
const extensionsScanner = scanOptions.useCache && !extensionsScannerInput.devMode && extensionsScannerInput.excludeObsolete ? this.userExtensionsCachedScanner : this.extensionsScanner;
198+
const extensionsScannerInput = await this.createExtensionScannerInput(location, !!scanOptions.profileLocation, ExtensionType.User, scanOptions.language, true, profileScanOptions, scanOptions.productVersion ?? this.getProductVersion());
199+
const extensionsScanner = scanOptions.useCache && !extensionsScannerInput.devMode ? this.userExtensionsCachedScanner : this.extensionsScanner;
204200
let extensions: IRelaxedScannedExtension[];
205201
try {
206202
extensions = await extensionsScanner.scanExtensions(extensionsScannerInput);
@@ -221,7 +217,7 @@ export abstract class AbstractExtensionsScannerService extends Disposable implem
221217
if (this.environmentService.isExtensionDevelopment && this.environmentService.extensionDevelopmentLocationURI) {
222218
const extensions = (await Promise.all(this.environmentService.extensionDevelopmentLocationURI.filter(extLoc => extLoc.scheme === Schemas.file)
223219
.map(async extensionDevelopmentLocationURI => {
224-
const input = await this.createExtensionScannerInput(extensionDevelopmentLocationURI, false, ExtensionType.User, true, scanOptions.language, false /* do not validate */, undefined, scanOptions.productVersion ?? this.getProductVersion());
220+
const input = await this.createExtensionScannerInput(extensionDevelopmentLocationURI, false, ExtensionType.User, scanOptions.language, false /* do not validate */, undefined, scanOptions.productVersion ?? this.getProductVersion());
225221
const extensions = await this.extensionsScanner.scanOneOrMultipleExtensions(input);
226222
return extensions.map(extension => {
227223
// Override the extension type from the existing extensions
@@ -237,7 +233,7 @@ export abstract class AbstractExtensionsScannerService extends Disposable implem
237233
}
238234

239235
async scanExistingExtension(extensionLocation: URI, extensionType: ExtensionType, scanOptions: ScanOptions): Promise<IScannedExtension | null> {
240-
const extensionsScannerInput = await this.createExtensionScannerInput(extensionLocation, false, extensionType, true, scanOptions.language, true, undefined, scanOptions.productVersion ?? this.getProductVersion());
236+
const extensionsScannerInput = await this.createExtensionScannerInput(extensionLocation, false, extensionType, scanOptions.language, true, undefined, scanOptions.productVersion ?? this.getProductVersion());
241237
const extension = await this.extensionsScanner.scanExtension(extensionsScannerInput);
242238
if (!extension) {
243239
return null;
@@ -249,7 +245,7 @@ export abstract class AbstractExtensionsScannerService extends Disposable implem
249245
}
250246

251247
async scanOneOrMultipleExtensions(extensionLocation: URI, extensionType: ExtensionType, scanOptions: ScanOptions): Promise<IScannedExtension[]> {
252-
const extensionsScannerInput = await this.createExtensionScannerInput(extensionLocation, false, extensionType, true, scanOptions.language, true, undefined, scanOptions.productVersion ?? this.getProductVersion());
248+
const extensionsScannerInput = await this.createExtensionScannerInput(extensionLocation, false, extensionType, scanOptions.language, true, undefined, scanOptions.productVersion ?? this.getProductVersion());
253249
const extensions = await this.extensionsScanner.scanOneOrMultipleExtensions(extensionsScannerInput);
254250
return this.applyScanOptions(extensions, extensionType, scanOptions, true);
255251
}
@@ -405,7 +401,7 @@ export abstract class AbstractExtensionsScannerService extends Disposable implem
405401

406402
private async scanDefaultSystemExtensions(useCache: boolean, language: string | undefined): Promise<IRelaxedScannedExtension[]> {
407403
this.logService.trace('Started scanning system extensions');
408-
const extensionsScannerInput = await this.createExtensionScannerInput(this.systemExtensionsLocation, false, ExtensionType.System, true, language, true, undefined, this.getProductVersion());
404+
const extensionsScannerInput = await this.createExtensionScannerInput(this.systemExtensionsLocation, false, ExtensionType.System, language, true, undefined, this.getProductVersion());
409405
const extensionsScanner = useCache && !extensionsScannerInput.devMode ? this.systemExtensionsCachedScanner : this.extensionsScanner;
410406
const result = await extensionsScanner.scanExtensions(extensionsScannerInput);
411407
this.logService.trace('Scanned system extensions:', result.length);
@@ -435,7 +431,7 @@ export abstract class AbstractExtensionsScannerService extends Disposable implem
435431
break;
436432
}
437433
}
438-
const result = await Promise.all(devSystemExtensionsLocations.map(async location => this.extensionsScanner.scanExtension((await this.createExtensionScannerInput(location, false, ExtensionType.System, true, language, true, undefined, this.getProductVersion())))));
434+
const result = await Promise.all(devSystemExtensionsLocations.map(async location => this.extensionsScanner.scanExtension((await this.createExtensionScannerInput(location, false, ExtensionType.System, language, true, undefined, this.getProductVersion())))));
439435
this.logService.trace('Scanned dev system extensions:', result.length);
440436
return coalesce(result);
441437
}
@@ -449,7 +445,7 @@ export abstract class AbstractExtensionsScannerService extends Disposable implem
449445
}
450446
}
451447

452-
private async createExtensionScannerInput(location: URI, profile: boolean, type: ExtensionType, excludeObsolete: boolean, language: string | undefined, validate: boolean, profileScanOptions: IProfileExtensionsScanOptions | undefined, productVersion: IProductVersion): Promise<ExtensionScannerInput> {
448+
private async createExtensionScannerInput(location: URI, profile: boolean, type: ExtensionType, language: string | undefined, validate: boolean, profileScanOptions: IProfileExtensionsScanOptions | undefined, productVersion: IProductVersion): Promise<ExtensionScannerInput> {
453449
const translations = await this.getTranslations(language ?? platform.language);
454450
const mtime = await this.getMtime(location);
455451
const applicationExtensionsLocation = profile && !this.uriIdentityService.extUri.isEqual(location, this.userDataProfilesService.defaultProfile.extensionsResource) ? this.userDataProfilesService.defaultProfile.extensionsResource : undefined;
@@ -462,7 +458,6 @@ export abstract class AbstractExtensionsScannerService extends Disposable implem
462458
profile,
463459
profileScanOptions,
464460
type,
465-
excludeObsolete,
466461
validate,
467462
productVersion.version,
468463
productVersion.date,
@@ -504,7 +499,6 @@ export class ExtensionScannerInput {
504499
public readonly profile: boolean,
505500
public readonly profileScanOptions: IProfileExtensionsScanOptions | undefined,
506501
public readonly type: ExtensionType,
507-
public readonly excludeObsolete: boolean,
508502
public readonly validate: boolean,
509503
public readonly productVersion: string,
510504
public readonly productDate: string | undefined,
@@ -534,7 +528,6 @@ export class ExtensionScannerInput {
534528
&& a.profile === b.profile
535529
&& objects.equals(a.profileScanOptions, b.profileScanOptions)
536530
&& a.type === b.type
537-
&& a.excludeObsolete === b.excludeObsolete
538531
&& a.validate === b.validate
539532
&& a.productVersion === b.productVersion
540533
&& a.productDate === b.productDate
@@ -558,7 +551,6 @@ class ExtensionsScanner extends Disposable {
558551
private readonly extensionsEnabledWithApiProposalVersion: string[];
559552

560553
constructor(
561-
private readonly obsoleteFile: URI,
562554
@IExtensionsProfileScannerService protected readonly extensionsProfileScannerService: IExtensionsProfileScannerService,
563555
@IUriIdentityService protected readonly uriIdentityService: IUriIdentityService,
564556
@IFileService protected readonly fileService: IFileService,
@@ -571,15 +563,9 @@ class ExtensionsScanner extends Disposable {
571563
}
572564

573565
async scanExtensions(input: ExtensionScannerInput): Promise<IRelaxedScannedExtension[]> {
574-
const extensions = input.profile ? await this.scanExtensionsFromProfile(input) : await this.scanExtensionsFromLocation(input);
575-
let obsolete: IStringDictionary<boolean> = {};
576-
if (input.excludeObsolete && input.type === ExtensionType.User) {
577-
try {
578-
const raw = (await this.fileService.readFile(this.obsoleteFile)).value.toString();
579-
obsolete = JSON.parse(raw);
580-
} catch (error) { /* ignore */ }
581-
}
582-
return isEmptyObject(obsolete) ? extensions : extensions.filter(e => !obsolete[ExtensionKey.create(e).toString()]);
566+
return input.profile
567+
? this.scanExtensionsFromProfile(input)
568+
: this.scanExtensionsFromLocation(input);
583569
}
584570

585571
private async scanExtensionsFromLocation(input: ExtensionScannerInput): Promise<IRelaxedScannedExtension[]> {
@@ -596,7 +582,7 @@ class ExtensionsScanner extends Disposable {
596582
if (input.type === ExtensionType.User && basename(c.resource).indexOf('.') === 0) {
597583
return null;
598584
}
599-
const extensionScannerInput = new ExtensionScannerInput(c.resource, input.mtime, input.applicationExtensionslocation, input.applicationExtensionslocationMtime, input.profile, input.profileScanOptions, input.type, input.excludeObsolete, input.validate, input.productVersion, input.productDate, input.productCommit, input.devMode, input.language, input.translations);
585+
const extensionScannerInput = new ExtensionScannerInput(c.resource, input.mtime, input.applicationExtensionslocation, input.applicationExtensionslocationMtime, input.profile, input.profileScanOptions, input.type, input.validate, input.productVersion, input.productDate, input.productCommit, input.devMode, input.language, input.translations);
600586
return this.scanExtension(extensionScannerInput);
601587
}));
602588
return coalesce(extensions)
@@ -622,7 +608,7 @@ class ExtensionsScanner extends Disposable {
622608
const extensions = await Promise.all<IRelaxedScannedExtension | null>(
623609
scannedProfileExtensions.map(async extensionInfo => {
624610
if (filter(extensionInfo)) {
625-
const extensionScannerInput = new ExtensionScannerInput(extensionInfo.location, input.mtime, input.applicationExtensionslocation, input.applicationExtensionslocationMtime, input.profile, input.profileScanOptions, input.type, input.excludeObsolete, input.validate, input.productVersion, input.productDate, input.productCommit, input.devMode, input.language, input.translations);
611+
const extensionScannerInput = new ExtensionScannerInput(extensionInfo.location, input.mtime, input.applicationExtensionslocation, input.applicationExtensionslocationMtime, input.profile, input.profileScanOptions, input.type, input.validate, input.productVersion, input.productDate, input.productCommit, input.devMode, input.language, input.translations);
626612
return this.scanExtension(extensionScannerInput, extensionInfo.metadata);
627613
}
628614
return null;
@@ -891,7 +877,6 @@ class CachedExtensionsScanner extends ExtensionsScanner {
891877

892878
constructor(
893879
private readonly currentProfile: IUserDataProfile,
894-
obsoleteFile: URI,
895880
@IUserDataProfilesService private readonly userDataProfilesService: IUserDataProfilesService,
896881
@IExtensionsProfileScannerService extensionsProfileScannerService: IExtensionsProfileScannerService,
897882
@IUriIdentityService uriIdentityService: IUriIdentityService,
@@ -900,7 +885,7 @@ class CachedExtensionsScanner extends ExtensionsScanner {
900885
@IEnvironmentService environmentService: IEnvironmentService,
901886
@ILogService logService: ILogService
902887
) {
903-
super(obsoleteFile, extensionsProfileScannerService, uriIdentityService, fileService, productService, environmentService, logService);
888+
super(extensionsProfileScannerService, uriIdentityService, fileService, productService, environmentService, logService);
904889
}
905890

906891
override async scanExtensions(input: ExtensionScannerInput): Promise<IRelaxedScannedExtension[]> {

0 commit comments

Comments
 (0)