Skip to content

Commit 956208b

Browse files
committed
Revert "debt - adopt new fs.readdir with stat info"
This reverts commit da5fb7d.
1 parent 07e9310 commit 956208b

3 files changed

Lines changed: 13 additions & 60 deletions

File tree

src/vs/base/node/pfs.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,6 @@ export async function readdir(path: string): Promise<string[]> {
138138
return handleDirectoryChildren(await promisify(fs.readdir)(path));
139139
}
140140

141-
export async function readdirWithFileTypes(path: string): Promise<fs.Dirent[]> {
142-
const children = await promisify(fs.readdir)(path, { withFileTypes: true });
143-
144-
// Mac: uses NFD unicode form on disk, but we want NFC
145-
// See also https://github.com/nodejs/node/issues/2165
146-
if (platform.isMacintosh) {
147-
for (const child of children) {
148-
child.name = normalizeNFC(child.name);
149-
}
150-
}
151-
152-
return children;
153-
}
154-
155141
export function readdirSync(path: string): string[] {
156142
return handleDirectoryChildren(fs.readdirSync(path));
157143
}

src/vs/base/test/node/pfs/pfs.test.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { CancellationTokenSource } from 'vs/base/common/cancellation';
1616
import { isWindows, isLinux } from 'vs/base/common/platform';
1717
import { canNormalize } from 'vs/base/common/normalization';
1818
import { VSBuffer } from 'vs/base/common/buffer';
19-
import { join } from 'path';
2019

2120
const chunkSize = 64 * 1024;
2221
const readError = 'Error while reading';
@@ -387,31 +386,6 @@ suite('PFS', () => {
387386
}
388387
});
389388

390-
test('readdirWithFileTypes', async () => {
391-
if (canNormalize && typeof process.versions['electron'] !== 'undefined' /* needs electron */) {
392-
const id = uuid.generateUuid();
393-
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
394-
const testDir = join(parentDir, 'pfs', id);
395-
396-
const newDir = path.join(testDir, 'öäü');
397-
await pfs.mkdirp(newDir, 493);
398-
399-
await pfs.writeFile(join(testDir, 'somefile.txt'), 'contents');
400-
401-
assert.ok(fs.existsSync(newDir));
402-
403-
const children = await pfs.readdirWithFileTypes(testDir);
404-
405-
assert.equal(children.some(n => n.name === 'öäü'), true); // Mac always converts to NFD, so
406-
assert.equal(children.some(n => n.isDirectory()), true);
407-
408-
assert.equal(children.some(n => n.name === 'somefile.txt'), true);
409-
assert.equal(children.some(n => n.isFile()), true);
410-
411-
await pfs.rimraf(parentDir);
412-
}
413-
});
414-
415389
test('writeFile (string)', async () => {
416390
const smallData = 'Hello World';
417391
const bigData = (new Array(100 * 1024)).join('Large String\n');

src/vs/platform/files/node/diskFileSystemProvider.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { mkdir, open, close, read, write, fdatasync, Dirent, Stats } from 'fs';
6+
import { mkdir, open, close, read, write, fdatasync } from 'fs';
77
import { promisify } from 'util';
88
import { IDisposable, Disposable, toDisposable, dispose, combinedDisposable } from 'vs/base/common/lifecycle';
99
import { IFileSystemProvider, FileSystemProviderCapabilities, IFileChange, IWatchOptions, IStat, FileType, FileDeleteOptions, FileOverwriteOptions, FileWriteOptions, FileOpenOptions, FileSystemProviderErrorCode, createFileSystemProviderError, FileSystemProviderError } from 'vs/platform/files/common/files';
1010
import { URI } from 'vs/base/common/uri';
1111
import { Event, Emitter } from 'vs/base/common/event';
1212
import { isLinux, isWindows } from 'vs/base/common/platform';
13-
import { statLink, unlink, move, copy, readFile, truncate, rimraf, RimRafMode, exists, readdirWithFileTypes } from 'vs/base/node/pfs';
13+
import { statLink, readdir, unlink, move, copy, readFile, truncate, rimraf, RimRafMode, exists } from 'vs/base/node/pfs';
1414
import { normalize, basename, dirname } from 'vs/base/common/path';
1515
import { joinPath } from 'vs/base/common/resources';
1616
import { isEqual } from 'vs/base/common/extpath';
@@ -62,8 +62,15 @@ export class DiskFileSystemProvider extends Disposable implements IFileSystemPro
6262
try {
6363
const { stat, isSymbolicLink } = await statLink(this.toFilePath(resource)); // cannot use fs.stat() here to support links properly
6464

65+
let type: number;
66+
if (isSymbolicLink) {
67+
type = FileType.SymbolicLink | (stat.isDirectory() ? FileType.Directory : FileType.File);
68+
} else {
69+
type = stat.isFile() ? FileType.File : stat.isDirectory() ? FileType.Directory : FileType.Unknown;
70+
}
71+
6572
return {
66-
type: this.toType(stat, isSymbolicLink),
73+
type,
6774
ctime: stat.ctime.getTime(),
6875
mtime: stat.mtime.getTime(),
6976
size: stat.size
@@ -75,19 +82,13 @@ export class DiskFileSystemProvider extends Disposable implements IFileSystemPro
7582

7683
async readdir(resource: URI): Promise<[string, FileType][]> {
7784
try {
78-
const children = await readdirWithFileTypes(this.toFilePath(resource));
85+
const children = await readdir(this.toFilePath(resource));
7986

8087
const result: [string, FileType][] = [];
8188
await Promise.all(children.map(async child => {
8289
try {
83-
let type: FileType;
84-
if (child.isSymbolicLink()) {
85-
type = (await this.stat(joinPath(resource, child.name))).type; // always resolve target the link points to if any
86-
} else {
87-
type = this.toType(child);
88-
}
89-
90-
result.push([child.name, type]);
90+
const stat = await this.stat(joinPath(resource, child));
91+
result.push([child, stat.type]);
9192
} catch (error) {
9293
this.logService.trace(error); // ignore errors for individual entries that can arise from permission denied
9394
}
@@ -99,14 +100,6 @@ export class DiskFileSystemProvider extends Disposable implements IFileSystemPro
99100
}
100101
}
101102

102-
private toType(entry: Stats | Dirent, isSymbolicLink = entry.isSymbolicLink()): FileType {
103-
if (isSymbolicLink) {
104-
return FileType.SymbolicLink | (entry.isDirectory() ? FileType.Directory : FileType.File);
105-
}
106-
107-
return entry.isFile() ? FileType.File : entry.isDirectory() ? FileType.Directory : FileType.Unknown;
108-
}
109-
110103
//#endregion
111104

112105
//#region File Reading/Writing

0 commit comments

Comments
 (0)