From 8b76bd2944e552db677c89d57c43edb5ad24ed39 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 3 Apr 2019 13:54:02 -0700 Subject: [PATCH 1/2] Don't recursively list directories in realCasePath() We only need to list the path's immediate parent directory in order to find its real case. Closes #636 --- CHANGELOG.md | 5 +++++ lib/src/executable/options.dart | 2 +- lib/src/io/interface.dart | 8 +++++--- lib/src/io/node.dart | 25 +++++++++++++++++-------- lib/src/io/vm.dart | 9 +++++---- pubspec.yaml | 2 +- 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4f16b81a..30021c62b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.17.5 + +* Avoid recursively listing directories when finding the canonical name of a + file on case-insensitive filesystems. + ## 1.17.4 * Consistently parse U+000C FORM FEED, U+000D CARRIAGE RETURN, and sequences of diff --git a/lib/src/executable/options.dart b/lib/src/executable/options.dart index 82ef17dac..e92e40fbd 100644 --- a/lib/src/executable/options.dart +++ b/lib/src/executable/options.dart @@ -356,7 +356,7 @@ class ExecutableOptions { /// [destination] directories. Map _listSourceDirectory(String source, String destination) { var map = {}; - for (var path in listDir(source)) { + for (var path in listDir(source, recursive: true)) { var basename = p.basename(path); if (basename.startsWith("_")) continue; diff --git a/lib/src/io/interface.dart b/lib/src/io/interface.dart index 16653d651..a41d3b14c 100644 --- a/lib/src/io/interface.dart +++ b/lib/src/io/interface.dart @@ -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 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 listDir(String path, {bool recursive = false}) => null; /// Returns the modification time of the file at [path]. DateTime modificationTime(String path) => null; diff --git a/lib/src/io/node.dart b/lib/src/io/node.dart index f7cec7bb5..8bb61fa2d 100644 --- a/lib/src/io/node.dart +++ b/lib/src/io/node.dart @@ -191,14 +191,23 @@ void ensureDir(String path) { }); } -Iterable listDir(String path) { - Iterable 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 listDir(String path, {bool recursive = false}) { + return _systemErrorToFileSystemException(() { + if (!recursive) { + return _fs + .readdirSync(parent) + .map((child) => p.join(parent, child as String)) + .where((path) => !dirExists(path)); + } else { + Iterable 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) => diff --git a/lib/src/io/vm.dart b/lib/src/io/vm.dart index 849f7dc9d..e439609c3 100644 --- a/lib/src/io/vm.dart +++ b/lib/src/io/vm.dart @@ -71,10 +71,11 @@ bool dirExists(String path) => io.Directory(path).existsSync(); void ensureDir(String path) => io.Directory(path).createSync(recursive: true); -Iterable listDir(String path) => io.Directory(path) - .listSync(recursive: true) - .where((entity) => entity is io.File) - .map((entity) => entity.path); +Iterable 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); diff --git a/pubspec.yaml b/pubspec.yaml index 38d4f6df0..938a624d9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass -version: 1.17.4 +version: 1.17.5-dev description: A Sass implementation in Dart. author: Dart Team homepage: https://github.com/sass/dart-sass From e51d47ee2a82cdd2c9b6e2fa6be523d3a40b4b38 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 3 Apr 2019 15:16:21 -0700 Subject: [PATCH 2/2] Fix a misnamed variable --- lib/src/io/node.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/io/node.dart b/lib/src/io/node.dart index 8bb61fa2d..77558b1b7 100644 --- a/lib/src/io/node.dart +++ b/lib/src/io/node.dart @@ -195,9 +195,9 @@ Iterable listDir(String path, {bool recursive = false}) { return _systemErrorToFileSystemException(() { if (!recursive) { return _fs - .readdirSync(parent) - .map((child) => p.join(parent, child as String)) - .where((path) => !dirExists(path)); + .readdirSync(path) + .map((child) => p.join(path, child as String)) + .where((child) => !dirExists(child)); } else { Iterable list(String parent) => _fs.readdirSync(parent).expand((child) {