Skip to content

Commit

Permalink
use fileservice.del (#181890)
Browse files Browse the repository at this point in the history
#181671 use fileservice.del
  • Loading branch information
sandy081 authored May 9, 2023
1 parent a54b497 commit 618dc85
Showing 1 changed file with 2 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { joinPath } from 'vs/base/common/resources';
import * as semver from 'vs/base/common/semver/semver';
import { isBoolean, isUndefined } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { generateUuid, isUUID } from 'vs/base/common/uuid';
import { generateUuid } from 'vs/base/common/uuid';
import * as pfs from 'vs/base/node/pfs';
import { extract, ExtractError, IFile, zip } from 'vs/base/node/zip';
import * as nls from 'vs/nls';
Expand Down Expand Up @@ -409,14 +409,11 @@ export class ExtensionsScanner extends Disposable {
private readonly _onExtract = this._register(new Emitter<URI>());
readonly onExtract = this._onExtract.event;

private cleanUpGeneratedFoldersPromise: Promise<void> = Promise.resolve();

constructor(
private readonly beforeRemovingExtension: (e: ILocalExtension) => Promise<void>,
@IFileService private readonly fileService: IFileService,
@IExtensionsScannerService private readonly extensionsScannerService: IExtensionsScannerService,
@IExtensionsProfileScannerService private readonly extensionsProfileScannerService: IExtensionsProfileScannerService,
@IUriIdentityService private readonly uriIdentityService: IUriIdentityService,
@ILogService private readonly logService: ILogService,
) {
super();
Expand All @@ -426,8 +423,6 @@ export class ExtensionsScanner extends Disposable {

async cleanUp(): Promise<void> {
await this.removeUninstalledExtensions();
this.cleanUpGeneratedFoldersPromise = this.cleanUpGeneratedFoldersPromise.then(() => this.removeGeneratedFolders());
await this.cleanUpGeneratedFoldersPromise;
}

async scanExtensions(type: ExtensionType | null, profileLocation: URI): Promise<ILocalExtension[]> {
Expand Down Expand Up @@ -460,8 +455,6 @@ export class ExtensionsScanner extends Disposable {
}

async extractUserExtension(extensionKey: ExtensionKey, zipPath: string, metadata: Metadata, token: CancellationToken): Promise<ILocalExtension> {
await this.cleanUpGeneratedFoldersPromise.catch(() => undefined);

const folderName = extensionKey.toString();
const tempPath = path.join(this.extensionsScannerService.userExtensionsLocation.fsPath, `.${generateUuid()}`);
const extensionPath = path.join(this.extensionsScannerService.userExtensionsLocation.fsPath, folderName);
Expand Down Expand Up @@ -531,9 +524,7 @@ export class ExtensionsScanner extends Disposable {

async removeExtension(extension: ILocalExtension | IScannedExtension, type: string): Promise<void> {
this.logService.trace(`Deleting ${type} extension from disk`, extension.identifier.id, extension.location.fsPath);
const renamedLocation = this.uriIdentityService.extUri.joinPath(this.uriIdentityService.extUri.dirname(extension.location), `.${generateUuid()}`);
await this.rename(extension.identifier, extension.location.fsPath, renamedLocation.fsPath, Date.now() + (2 * 60 * 1000) /* Retry for 2 minutes */);
await this.fileService.del(renamedLocation, { recursive: true });
await this.fileService.del(extension.location, { recursive: true });
this.logService.info('Deleted from disk', extension.identifier.id, extension.location.fsPath);
}

Expand Down Expand Up @@ -694,33 +685,6 @@ export class ExtensionsScanner extends Disposable {
await Promise.allSettled(toRemove.map(e => this.removeUninstalledExtension(e)));
}

private async removeGeneratedFolders(): Promise<void> {
this.logService.trace('ExtensionManagementService#removeGeneratedFolders');
const promises: Promise<any>[] = [];
let stat;
try {
stat = await this.fileService.resolve(this.extensionsScannerService.userExtensionsLocation);
} catch (error) {
if (toFileOperationResult(error) !== FileOperationResult.FILE_NOT_FOUND) {
this.logService.error(error);
}
}
for (const child of stat?.children ?? []) {
if (child.isDirectory && child.name.startsWith('.') && isUUID(child.name.substring(1))) {
promises.push((async () => {
this.logService.trace('Deleting the generated extension folder', child.resource.toString());
try {
await this.fileService.del(child.resource, { recursive: true });
this.logService.info('Deleted the generated extension folder', child.resource.toString());
} catch (error) {
this.logService.error(error);
}
})());
}
}
await Promise.allSettled(promises);
}

private joinErrors(errorOrErrors: (Error | string) | (Array<Error | string>)): Error {
const errors = Array.isArray(errorOrErrors) ? errorOrErrors : [errorOrErrors];
if (errors.length === 1) {
Expand Down

0 comments on commit 618dc85

Please sign in to comment.