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; |