Skip to content

Commit

Permalink
Don't recursively list directories in realCasePath() (#641)
Browse files Browse the repository at this point in the history
We only need to list the path's immediate parent directory in order to
find its real case.

Closes #636
  • Loading branch information
nex3 authored Apr 4, 2019
1 parent 495c6f3 commit 59800ad
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/executable/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 5 additions & 3 deletions lib/src/io/interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 17 additions & 8 deletions lib/src/io/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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];
});

return _systemErrorToFileSystemException(() => list(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 list(path);
}
});
}

DateTime modificationTime(String path) =>
Expand Down
9 changes: 5 additions & 4 deletions lib/src/io/vm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 59800ad

Please sign in to comment.