提交 aab05a86 编写于 作者: B Benjamin Pasero

Hot Exit: avoid direct calls to fs.readdir()/fs.readdirSync() (fixes #14055)

上级 4dc59b7e
......@@ -16,11 +16,21 @@ import paths = require('path');
const loop = flow.loop;
export function readdirSync(path: string): string[] {
// Mac: uses NFD unicode form on disk, but we want NFC
// See also https://github.com/nodejs/node/issues/2165
if (platform.isMacintosh) {
return fs.readdirSync(path).map(c => strings.normalizeNFC(c));
}
return fs.readdirSync(path);
}
export function readdir(path: string, callback: (error: Error, files: string[]) => void): void {
// Mac: uses NFD unicode form on disk, but we want NFC
// See also https://github.com/nodejs/node/issues/2165
if (platform.isMacintosh) {
return readdirNormalize(path, (error, children) => {
return fs.readdir(path, (error, children) => {
if (error) {
return callback(error, null);
}
......@@ -29,22 +39,7 @@ export function readdir(path: string, callback: (error: Error, files: string[])
});
}
return readdirNormalize(path, callback);
}
function readdirNormalize(path: string, callback: (error: Error, files: string[]) => void): void {
fs.readdir(path, (error, children) => {
if (error) {
return callback(error, null);
}
// Bug in node: In some environments we get "." and ".." as entries from the call to readdir().
// For example Sharepoint via WebDav on Windows includes them. We never want those
// entries in the result set though because they are not valid children of the folder
// for our concerns.
// See https://github.com/nodejs/node/issues/4002
return callback(null, children.filter(c => c !== '.' && c !== '..'));
});
return fs.readdir(path, callback);
}
export function mkdirp(path: string, mode: number, callback: (error: Error) => void): void {
......
......@@ -10,6 +10,7 @@ import * as crypto from 'crypto';
import * as arrays from 'vs/base/common/arrays';
import fs = require('fs');
import pfs = require('vs/base/node/pfs');
import { readdirSync } from 'vs/base/node/extfs';
import Uri from 'vs/base/common/uri';
import { IBackupService } from 'vs/platform/backup/common/backup';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
......@@ -109,7 +110,7 @@ export class BackupService implements IBackupService {
// Allow sync here as it's only used in workbench initialization's critical path
try {
return fs.readdirSync(untitledDir).map(file => path.join(untitledDir, file));
return readdirSync(untitledDir).map(file => path.join(untitledDir, file));
} catch (ex) {
return [];
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册