From b28cd23d521059938e08515618cdc670f3baa79b Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 3 Feb 2021 11:29:26 +0100 Subject: [PATCH] fs - more removal of promisify utility --- src/vs/base/node/extpath.ts | 5 ++--- src/vs/base/node/pfs.ts | 5 ++--- src/vs/base/node/processes.ts | 6 +++--- src/vs/platform/files/node/diskFileSystemProvider.ts | 4 ++-- src/vs/workbench/api/node/extHostTunnelService.ts | 3 +-- .../contrib/performance/electron-browser/startupTimings.ts | 5 ++--- src/vs/workbench/services/extensions/node/proxyResolver.ts | 3 +-- 7 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/vs/base/node/extpath.ts b/src/vs/base/node/extpath.ts index 0096544ada5d6..b43c407d519a8 100644 --- a/src/vs/base/node/extpath.ts +++ b/src/vs/base/node/extpath.ts @@ -7,7 +7,6 @@ import * as fs from 'fs'; import { rtrim } from 'vs/base/common/strings'; import { sep, join, normalize, dirname, basename } from 'vs/base/common/path'; import { readdirSync } from 'vs/base/node/pfs'; -import { promisify } from 'util'; /** * Copied from: https://github.com/microsoft/vscode-node-debug/blob/master/src/node/pathUtilities.ts#L83 @@ -53,7 +52,7 @@ export function realcaseSync(path: string): string | null { export async function realpath(path: string): Promise { try { - return await promisify(fs.realpath)(path); + return await fs.promises.realpath(path); } catch (error) { // We hit an error calling fs.realpath(). Since fs.realpath() is doing some path normalization @@ -63,7 +62,7 @@ export async function realpath(path: string): Promise { // to not resolve links but to simply see if the path is read accessible or not. const normalizedPath = normalizePath(path); - await promisify(fs.access)(normalizedPath, fs.constants.R_OK); + await fs.promises.access(normalizedPath, fs.constants.R_OK); return normalizedPath; } diff --git a/src/vs/base/node/pfs.ts b/src/vs/base/node/pfs.ts index f9ec30338703b..7794ebf1017ea 100644 --- a/src/vs/base/node/pfs.ts +++ b/src/vs/base/node/pfs.ts @@ -9,7 +9,6 @@ import { join } from 'vs/base/common/path'; import { Queue } from 'vs/base/common/async'; import { isMacintosh, isWindows } from 'vs/base/common/platform'; import { Event } from 'vs/base/common/event'; -import { promisify } from 'util'; import { isRootOrDriveLetter } from 'vs/base/common/extpath'; import { generateUuid } from 'vs/base/common/uuid'; import { normalizeNFC } from 'vs/base/common/normalization'; @@ -95,11 +94,11 @@ export function rimrafSync(path: string): void { //#region readdir with NFC support (macos) export async function readdir(path: string): Promise { - return handleDirectoryChildren(await promisify(fs.readdir)(path)); + return handleDirectoryChildren(await fs.promises.readdir(path)); } export async function readdirWithFileTypes(path: string): Promise { - const children = await promisify(fs.readdir)(path, { withFileTypes: true }); + const children = await fs.promises.readdir(path, { withFileTypes: true }); // Mac: uses NFD unicode form on disk, but we want NFC // See also https://github.com/nodejs/node/issues/2165 diff --git a/src/vs/base/node/processes.ts b/src/vs/base/node/processes.ts index de16ce24d00f0..72c1a613a2801 100644 --- a/src/vs/base/node/processes.ts +++ b/src/vs/base/node/processes.ts @@ -5,7 +5,7 @@ import * as path from 'vs/base/common/path'; import * as fs from 'fs'; -import { promisify } from 'util'; +import * as pfs from 'vs/base/node/pfs'; import * as cp from 'child_process'; import * as nls from 'vs/nls'; import * as Types from 'vs/base/common/types'; @@ -456,8 +456,8 @@ export namespace win32 { } async function fileExists(path: string): Promise { - if (await promisify(fs.exists)(path)) { - return !((await promisify(fs.stat)(path)).isDirectory()); + if (await pfs.exists(path)) { + return !((await fs.promises.stat(path)).isDirectory()); } return false; } diff --git a/src/vs/platform/files/node/diskFileSystemProvider.ts b/src/vs/platform/files/node/diskFileSystemProvider.ts index 805ad200e1c04..4544c8f4edd74 100644 --- a/src/vs/platform/files/node/diskFileSystemProvider.ts +++ b/src/vs/platform/files/node/diskFileSystemProvider.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { mkdir, open, close, read, write, fdatasync, Dirent, Stats, promises } from 'fs'; +import { open, close, read, write, fdatasync, Dirent, Stats, promises } from 'fs'; import { promisify } from 'util'; import { IDisposable, Disposable, toDisposable, dispose, combinedDisposable } from 'vs/base/common/lifecycle'; import { FileSystemProviderCapabilities, IFileChange, IWatchOptions, IStat, FileType, FileDeleteOptions, FileOverwriteOptions, FileWriteOptions, FileOpenOptions, FileSystemProviderErrorCode, createFileSystemProviderError, FileSystemProviderError, IFileSystemProviderWithFileReadWriteCapability, IFileSystemProviderWithFileReadStreamCapability, IFileSystemProviderWithOpenReadWriteCloseCapability, FileReadStreamOptions, IFileSystemProviderWithFileFolderCopyCapability } from 'vs/platform/files/common/files'; @@ -400,7 +400,7 @@ export class DiskFileSystemProvider extends Disposable implements async mkdir(resource: URI): Promise { try { - await promisify(mkdir)(this.toFilePath(resource)); + await promises.mkdir(this.toFilePath(resource)); } catch (error) { throw this.toFileSystemProviderError(error); } diff --git a/src/vs/workbench/api/node/extHostTunnelService.ts b/src/vs/workbench/api/node/extHostTunnelService.ts index 7d2daea716ddb..5b079fa0cf1da 100644 --- a/src/vs/workbench/api/node/extHostTunnelService.ts +++ b/src/vs/workbench/api/node/extHostTunnelService.ts @@ -18,7 +18,6 @@ import { IExtHostTunnelService, TunnelDto } from 'vs/workbench/api/common/extHos import { Event, Emitter } from 'vs/base/common/event'; import { TunnelOptions, TunnelCreationOptions } from 'vs/platform/remote/common/tunnel'; import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'; -import { promisify } from 'util'; import { MovingAverage } from 'vs/base/common/numbers'; import { CandidatePort } from 'vs/workbench/services/remote/common/remoteExplorerService'; import { ILogService } from 'vs/platform/log/common/log'; @@ -288,7 +287,7 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe const childUri = resources.joinPath(URI.file('/proc'), childName); const childStat = await fs.promises.stat(childUri.fsPath); if (childStat.isDirectory() && !isNaN(pid)) { - const cwd = await promisify(fs.readlink)(resources.joinPath(childUri, 'cwd').fsPath); + const cwd = await fs.promises.readlink(resources.joinPath(childUri, 'cwd').fsPath); const cmd = await fs.promises.readFile(resources.joinPath(childUri, 'cmdline').fsPath, 'utf8'); processes.push({ pid, cwd, cmd }); } diff --git a/src/vs/workbench/contrib/performance/electron-browser/startupTimings.ts b/src/vs/workbench/contrib/performance/electron-browser/startupTimings.ts index 47c85ed5304cb..2bbb3f6ece455 100644 --- a/src/vs/workbench/contrib/performance/electron-browser/startupTimings.ts +++ b/src/vs/workbench/contrib/performance/electron-browser/startupTimings.ts @@ -3,9 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { appendFile } from 'fs'; +import { promises } from 'fs'; import { timeout } from 'vs/base/common/async'; -import { promisify } from 'util'; import { onUnexpectedError } from 'vs/base/common/errors'; import { isCodeEditor } from 'vs/editor/browser/editorBrowser'; import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/environmentService'; @@ -58,7 +57,7 @@ export class StartupTimings implements IWorkbenchContribution { this._timerService.whenReady(), timeout(15000), // wait: cached data creation, telemetry sending ]).then(() => { - return promisify(appendFile)(appendTo, `${this._timerService.startupMetrics.ellapsed}\t${this._productService.nameShort}\t${(this._productService.commit || '').slice(0, 10) || '0000000000'}\t${sessionId}\t${standardStartupError === undefined ? 'standard_start' : 'NO_standard_start : ' + standardStartupError}\n`); + return promises.appendFile(appendTo, `${this._timerService.startupMetrics.ellapsed}\t${this._productService.nameShort}\t${(this._productService.commit || '').slice(0, 10) || '0000000000'}\t${sessionId}\t${standardStartupError === undefined ? 'standard_start' : 'NO_standard_start : ' + standardStartupError}\n`); }).then(() => { this._nativeHostService.quit(); }).catch(err => { diff --git a/src/vs/workbench/services/extensions/node/proxyResolver.ts b/src/vs/workbench/services/extensions/node/proxyResolver.ts index d520ce8bd0552..36aa0fbd61c1a 100644 --- a/src/vs/workbench/services/extensions/node/proxyResolver.ts +++ b/src/vs/workbench/services/extensions/node/proxyResolver.ts @@ -18,7 +18,6 @@ import { MainThreadTelemetryShape, IInitData } from 'vs/workbench/api/common/ext import { toErrorMessage } from 'vs/base/common/errorMessage'; import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService'; import { URI } from 'vs/base/common/uri'; -import { promisify } from 'util'; import { ILogService } from 'vs/platform/log/common/log'; import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'; @@ -540,7 +539,7 @@ const linuxCaCertificatePaths = [ async function readLinuxCaCertificates() { for (const certPath of linuxCaCertificatePaths) { try { - const content = await promisify(fs.readFile)(certPath, { encoding: 'utf8' }); + const content = await fs.promises.readFile(certPath, { encoding: 'utf8' }); const certs = new Set(content.split(/(?=-----BEGIN CERTIFICATE-----)/g) .filter(pem => !!pem.length)); return {