Don't recursively list directories in realCasePath() (#641)

We only need to list the path's immediate parent directory in order to
find its real case.

Closes #636
This commit is contained in:
Natalie Weizenbaum 2019-04-04 12:18:02 -07:00 committed by GitHub
parent 495c6f3163
commit 59800ad1f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 15 deletions

View File

@ -1,5 +1,8 @@
## 1.17.5
* Avoid recursively listing directories when finding the canonical name of a
file on case-insensitive filesystems.
* Fix importing files relative to `package:`-imported files.
* Don't claim that "package:" URLs aren't supported when they actually are.

View File

@ -356,7 +356,7 @@ class ExecutableOptions {
/// [destination] directories.
Map<String, String> _listSourceDirectory(String source, String destination) {
var map = <String, String>{};
for (var path in listDir(source)) {
for (var path in listDir(source, recursive: true)) {
var basename = p.basename(path);
if (basename.startsWith("_")) continue;

View File

@ -79,9 +79,11 @@ bool dirExists(String path) => null;
/// necessary.
void ensureDir(String path) => null;
/// Recursively lists the files (not sub-directories) of the directory at
/// [path].
Iterable<String> listDir(String path) => null;
/// Lists the files (not sub-directories) in the directory at [path].
///
/// If [recursive] is `true`, this lists files in directories transitively
/// beneath [path] as well.
Iterable<String> listDir(String path, {bool recursive = false}) => null;
/// Returns the modification time of the file at [path].
DateTime modificationTime(String path) => null;

View File

@ -191,14 +191,23 @@ void ensureDir(String path) {
});
}
Iterable<String> listDir(String path) {
Iterable<String> list(String parent) =>
_fs.readdirSync(parent).expand((child) {
var path = p.join(parent, child as String);
return dirExists(path) ? listDir(path) : [path];
});
Iterable<String> listDir(String path, {bool recursive = false}) {
return _systemErrorToFileSystemException(() {
if (!recursive) {
return _fs
.readdirSync(path)
.map((child) => p.join(path, child as String))
.where((child) => !dirExists(child));
} else {
Iterable<String> list(String parent) =>
_fs.readdirSync(parent).expand((child) {
var path = p.join(parent, child as String);
return dirExists(path) ? list(path) : [path];
});
return _systemErrorToFileSystemException(() => list(path));
return list(path);
}
});
}
DateTime modificationTime(String path) =>

View File

@ -71,10 +71,11 @@ bool dirExists(String path) => io.Directory(path).existsSync();
void ensureDir(String path) => io.Directory(path).createSync(recursive: true);
Iterable<String> listDir(String path) => io.Directory(path)
.listSync(recursive: true)
.where((entity) => entity is io.File)
.map((entity) => entity.path);
Iterable<String> listDir(String path, {bool recursive = false}) =>
io.Directory(path)
.listSync(recursive: recursive)
.where((entity) => entity is io.File)
.map((entity) => entity.path);
DateTime modificationTime(String path) {
var stat = io.FileStat.statSync(path);