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

Unified Diff: pkg/glob/lib/src/list_tree.dart

Issue 725263002: Fix a bogus exception in Glob. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | « pkg/glob/CHANGELOG.md ('k') | pkg/glob/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/glob/lib/src/list_tree.dart
diff --git a/pkg/glob/lib/src/list_tree.dart b/pkg/glob/lib/src/list_tree.dart
index 44eaaf39ad3ecda0d94d193fad0cc13453683cfd..bf6f7a4a73d023c3aa45064f9b22b34336a00e0d 100644
--- a/pkg/glob/lib/src/list_tree.dart
+++ b/pkg/glob/lib/src/list_tree.dart
@@ -13,6 +13,11 @@ import 'ast.dart';
import 'stream_pool.dart';
import 'utils.dart';
+/// The errno for a file or directory not existing.
+///
+/// This is consistent across platforms.
+const _ENOENT = 2;
+
/// A structure built from a glob that efficiently lists filesystem entities
/// that match that glob.
///
@@ -319,8 +324,16 @@ class _ListTreeNode {
children.forEach((sequence, child) {
if (entity is! Directory) return;
if (!sequence.matches(basename)) return;
- resultPool.add(child.list(p.join(dir, basename),
- followLinks: followLinks));
+ var stream = child.list(p.join(dir, basename), followLinks: followLinks)
+ .handleError((_) {}, test: (error) {
+ // Ignore errors from directories not existing. We do this here so
+ // that we only ignore warnings below wild cards. For example, the
+ // glob "foo/bar/*/baz" should fail if "foo/bar" doesn't exist but
+ // succeed if "foo/bar/qux/baz" doesn't exist.
+ return error is FileSystemException &&
+ error.osError.errorCode == _ENOENT;
+ });
+ resultPool.add(stream);
});
},
onError: resultController.addError,
@@ -361,8 +374,20 @@ class _ListTreeNode {
entities.addAll(children.keys
.where((sequence) => sequence.matches(basename))
.expand((sequence) {
- return children[sequence].listSync(
- p.join(dir, basename), followLinks: followLinks);
+ try {
+ return children[sequence].listSync(
+ p.join(dir, basename), followLinks: followLinks).toList();
+ } on FileSystemException catch (error) {
+ // Ignore errors from directories not existing. We do this here so
+ // that we only ignore warnings below wild cards. For example, the
+ // glob "foo/bar/*/baz" should fail if "foo/bar" doesn't exist but
+ // succeed if "foo/bar/qux/baz" doesn't exist.
+ if (error.osError.errorCode == _ENOENT) {
+ return const [];
+ } else {
+ rethrow;
+ }
+ }
}));
return entities;
« no previous file with comments | « pkg/glob/CHANGELOG.md ('k') | pkg/glob/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698