Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(834)

Unified Diff: sdk/lib/_internal/pub/lib/src/io.dart

Issue 211373003: Speed up directory listing in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/test/io_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/io.dart
diff --git a/sdk/lib/_internal/pub/lib/src/io.dart b/sdk/lib/_internal/pub/lib/src/io.dart
index 1186cdeb86f012299ca5fc7ba3663b0df7c9bb52..d50e06860ae40981b4ab0e2ce948c5301fe13809 100644
--- a/sdk/lib/_internal/pub/lib/src/io.dart
+++ b/sdk/lib/_internal/pub/lib/src/io.dart
@@ -242,44 +242,25 @@ String createSystemTempDir() {
/// contents (defaults to `false`). If [includeHidden] is `true`, includes files
/// and directories beginning with `.` (defaults to `false`).
///
+/// Note that dart:io handles recursive symlinks in an unfortunate way. You
+/// end up with two copies of every entity that is within the recursive loop.
+/// We originally had our own directory list code that addressed that, but it
+/// had a noticeable performance impact. In the interest of speed, we'll just
+/// live with that annoying behavior.
+///
/// The returned paths are guaranteed to begin with [dir].
List<String> listDir(String dir, {bool recursive: false,
bool includeHidden: false}) {
- List<String> doList(String dir, Set<String> listedDirectories) {
- var contents = <String>[];
-
- // Avoid recursive symlinks.
- var resolvedPath = canonicalize(dir);
- if (listedDirectories.contains(resolvedPath)) return [];
-
- listedDirectories = new Set<String>.from(listedDirectories);
- listedDirectories.add(resolvedPath);
-
- log.io("Listing directory $dir.");
+ var entities = new Directory(dir).listSync(recursive: recursive);
- var children = <String>[];
- for (var entity in new Directory(dir).listSync()) {
- if (!includeHidden && path.basename(entity.path).startsWith('.')) {
- continue;
- }
-
- contents.add(entity.path);
- if (entity is Directory) {
- // TODO(nweiz): don't manually recurse once issue 4794 is fixed.
- // Note that once we remove the manual recursion, we'll need to
- // explicitly filter out files in hidden directories.
- if (recursive) {
- children.addAll(doList(entity.path, listedDirectories));
- }
- }
- }
+ isHidden(part) => part.startsWith(".") && part != "." && part != "..";
- log.fine("Listed directory $dir:\n${contents.join('\n')}");
- contents.addAll(children);
- return contents;
+ if (!includeHidden) {
+ entities = entities.where(
+ (entity) => !path.split(entity.path).any(isHidden));
}
- return doList(dir, new Set<String>());
+ return entities.map((entity) => entity.path).toList();
}
/// Returns whether [dir] exists on the file system. This will return `true` for
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/test/io_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698