OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library glob.list_tree; | 5 library glob.list_tree; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 | 9 |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
11 | 11 |
12 import 'ast.dart'; | 12 import 'ast.dart'; |
13 import 'stream_pool.dart'; | 13 import 'stream_pool.dart'; |
| 14 import 'utils.dart'; |
14 | 15 |
15 /// A structure built from a glob that efficiently lists filesystem entities | 16 /// A structure built from a glob that efficiently lists filesystem entities |
16 /// that match that glob. | 17 /// that match that glob. |
17 /// | 18 /// |
18 /// This structure is designed to list the minimal number of physical | 19 /// This structure is designed to list the minimal number of physical |
19 /// directories necessary to find everything that matches the glob. For example, | 20 /// directories necessary to find everything that matches the glob. For example, |
20 /// for the glob `foo/{bar,baz}/*`, there's no need to list the working | 21 /// for the glob `foo/{bar,baz}/*`, there's no need to list the working |
21 /// directory or even `foo/`; only `foo/bar` and `foo/baz` should be listed. | 22 /// directory or even `foo/`; only `foo/bar` and `foo/baz` should be listed. |
22 /// | 23 /// |
23 /// This works by creating a tree of [_ListTreeNode]s, each of which corresponds | 24 /// This works by creating a tree of [_ListTreeNode]s, each of which corresponds |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 p.join(dir, basename), followLinks: followLinks); | 365 p.join(dir, basename), followLinks: followLinks); |
365 })); | 366 })); |
366 | 367 |
367 return entities; | 368 return entities; |
368 }); | 369 }); |
369 } | 370 } |
370 | 371 |
371 /// Returns whether the native [path] matches [_validator]. | 372 /// Returns whether the native [path] matches [_validator]. |
372 bool _matches(String path) { | 373 bool _matches(String path) { |
373 if (_validator == null) return false; | 374 if (_validator == null) return false; |
374 return _validator.matches(path); | 375 return _validator.matches(toPosixPath(p.context, path)); |
375 } | 376 } |
376 | 377 |
377 String toString() => "($_validator) $children"; | 378 String toString() => "($_validator) $children"; |
378 } | 379 } |
379 | 380 |
380 /// Joins each [components] into a new glob where each component is separated by | 381 /// Joins each [components] into a new glob where each component is separated by |
381 /// a path separator. | 382 /// a path separator. |
382 SequenceNode _join(Iterable<AstNode> components) { | 383 SequenceNode _join(Iterable<AstNode> components) { |
383 var componentsList = components.toList(); | 384 var componentsList = components.toList(); |
384 var nodes = [componentsList.removeAt(0)]; | 385 var nodes = [componentsList.removeAt(0)]; |
385 for (var component in componentsList) { | 386 for (var component in componentsList) { |
386 nodes.add(new LiteralNode('/')); | 387 nodes.add(new LiteralNode('/')); |
387 nodes.add(component); | 388 nodes.add(component); |
388 } | 389 } |
389 return new SequenceNode(nodes); | 390 return new SequenceNode(nodes); |
390 } | 391 } |
OLD | NEW |