Skip to content

Commit 547c1a7

Browse files
committed
Revert "Hot Exit: avoid direct calls to fs.readdir()/fs.readdirSync() (fixes microsoft#14055)"
This reverts commit aab05a8.
1 parent 2066424 commit 547c1a7

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

src/vs/base/node/extfs.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,11 @@ import paths = require('path');
1616

1717
const loop = flow.loop;
1818

19-
export function readdirSync(path: string): string[] {
20-
// Mac: uses NFD unicode form on disk, but we want NFC
21-
// See also https://github.com/nodejs/node/issues/2165
22-
if (platform.isMacintosh) {
23-
return fs.readdirSync(path).map(c => strings.normalizeNFC(c));
24-
}
25-
26-
return fs.readdirSync(path);
27-
}
28-
2919
export function readdir(path: string, callback: (error: Error, files: string[]) => void): void {
3020
// Mac: uses NFD unicode form on disk, but we want NFC
3121
// See also https://github.com/nodejs/node/issues/2165
3222
if (platform.isMacintosh) {
33-
return fs.readdir(path, (error, children) => {
23+
return readdirNormalize(path, (error, children) => {
3424
if (error) {
3525
return callback(error, null);
3626
}
@@ -39,7 +29,22 @@ export function readdir(path: string, callback: (error: Error, files: string[])
3929
});
4030
}
4131

42-
return fs.readdir(path, callback);
32+
return readdirNormalize(path, callback);
33+
}
34+
35+
function readdirNormalize(path: string, callback: (error: Error, files: string[]) => void): void {
36+
fs.readdir(path, (error, children) => {
37+
if (error) {
38+
return callback(error, null);
39+
}
40+
41+
// Bug in node: In some environments we get "." and ".." as entries from the call to readdir().
42+
// For example Sharepoint via WebDav on Windows includes them. We never want those
43+
// entries in the result set though because they are not valid children of the folder
44+
// for our concerns.
45+
// See https://github.com/nodejs/node/issues/4002
46+
return callback(null, children.filter(c => c !== '.' && c !== '..'));
47+
});
4348
}
4449

4550
export function mkdirp(path: string, mode: number, callback: (error: Error) => void): void {

src/vs/platform/backup/node/backupService.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import * as crypto from 'crypto';
1010
import * as arrays from 'vs/base/common/arrays';
1111
import fs = require('fs');
1212
import pfs = require('vs/base/node/pfs');
13-
import { readdirSync } from 'vs/base/node/extfs';
1413
import Uri from 'vs/base/common/uri';
1514
import { IBackupService } from 'vs/platform/backup/common/backup';
1615
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
@@ -110,7 +109,7 @@ export class BackupService implements IBackupService {
110109

111110
// Allow sync here as it's only used in workbench initialization's critical path
112111
try {
113-
return readdirSync(untitledDir).map(file => path.join(untitledDir, file));
112+
return fs.readdirSync(untitledDir).map(file => path.join(untitledDir, file));
114113
} catch (ex) {
115114
return [];
116115
}

0 commit comments

Comments
 (0)