@@ -16,21 +16,11 @@ import paths = require('path');
1616
1717const 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-
2919export 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
4550export function mkdirp ( path : string , mode : number , callback : ( error : Error ) => void ) : void {
0 commit comments