Skip to content

Commit

Permalink
fs - more removal of promisify utility
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Feb 3, 2021
1 parent dbf6147 commit b28cd23
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/vs/base/node/extpath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,7 +52,7 @@ export function realcaseSync(path: string): string | null {

export async function realpath(path: string): Promise<string> {
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
Expand All @@ -63,7 +62,7 @@ export async function realpath(path: string): Promise<string> {
// 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;
}
Expand Down
5 changes: 2 additions & 3 deletions src/vs/base/node/pfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -95,11 +94,11 @@ export function rimrafSync(path: string): void {
//#region readdir with NFC support (macos)

export async function readdir(path: string): Promise<string[]> {
return handleDirectoryChildren(await promisify(fs.readdir)(path));
return handleDirectoryChildren(await fs.promises.readdir(path));
}

export async function readdirWithFileTypes(path: string): Promise<fs.Dirent[]> {
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
Expand Down
6 changes: 3 additions & 3 deletions src/vs/base/node/processes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -456,8 +456,8 @@ export namespace win32 {
}

async function fileExists(path: string): Promise<boolean> {
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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/files/node/diskFileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -400,7 +400,7 @@ export class DiskFileSystemProvider extends Disposable implements

async mkdir(resource: URI): Promise<void> {
try {
await promisify(mkdir)(this.toFilePath(resource));
await promises.mkdir(this.toFilePath(resource));
} catch (error) {
throw this.toFileSystemProviderError(error);
}
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/api/node/extHostTunnelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 => {
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/services/extensions/node/proxyResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b28cd23

Please sign in to comment.