OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 descriptor.directory; | 5 library descriptor.directory; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:pathos/path.dart' as path; | 10 import 'package:pathos/path.dart' as path; |
(...skipping 28 matching lines...) Expand all Loading... |
39 'validating directory:\n${describe()}'); | 39 'validating directory:\n${describe()}'); |
40 | 40 |
41 Future validateNow([String parent]) { | 41 Future validateNow([String parent]) { |
42 if (parent == null) parent = defaultRoot; | 42 if (parent == null) parent = defaultRoot; |
43 var fullPath = path.join(parent, name); | 43 var fullPath = path.join(parent, name); |
44 if (!new Directory(fullPath).existsSync()) { | 44 if (!new Directory(fullPath).existsSync()) { |
45 throw "Directory not found: '$fullPath'."; | 45 throw "Directory not found: '$fullPath'."; |
46 } | 46 } |
47 | 47 |
48 return Future.wait(contents.map((entry) { | 48 return Future.wait(contents.map((entry) { |
49 return new Future.of(() => entry.validateNow(fullPath)) | 49 return new Future.sync(() => entry.validateNow(fullPath)) |
50 .then((_) => null) | 50 .then((_) => null) |
51 .catchError((e) => e); | 51 .catchError((e) => e); |
52 })).then((results) { | 52 })).then((results) { |
53 var errors = results.where((e) => e != null); | 53 var errors = results.where((e) => e != null); |
54 if (errors.isEmpty) return; | 54 if (errors.isEmpty) return; |
55 throw _DirectoryValidationError.merge(errors); | 55 throw _DirectoryValidationError.merge(errors); |
56 }); | 56 }); |
57 } | 57 } |
58 | 58 |
59 Stream<List<int>> load(String pathToLoad) { | 59 Stream<List<int>> load(String pathToLoad) { |
60 return futureStream(new Future.immediate(null).then((_) { | 60 return futureStream(new Future.value().then((_) { |
61 if (_path.isAbsolute(pathToLoad)) { | 61 if (_path.isAbsolute(pathToLoad)) { |
62 throw "Can't load absolute path '$pathToLoad'."; | 62 throw "Can't load absolute path '$pathToLoad'."; |
63 } | 63 } |
64 | 64 |
65 var split = _path.split(_path.normalize(pathToLoad)); | 65 var split = _path.split(_path.normalize(pathToLoad)); |
66 if (split.isEmpty || split.first == '.' || split.first == '..') { | 66 if (split.isEmpty || split.first == '.' || split.first == '..') { |
67 throw "Can't load '$pathToLoad' from within '$name'."; | 67 throw "Can't load '$pathToLoad' from within '$name'."; |
68 } | 68 } |
69 | 69 |
70 var matchingEntries = contents.where((entry) => | 70 var matchingEntries = contents.where((entry) => |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 _DirectoryValidationError(Iterable errors) | 122 _DirectoryValidationError(Iterable errors) |
123 : errors = errors.map((e) => e.toString()).toList(); | 123 : errors = errors.map((e) => e.toString()).toList(); |
124 | 124 |
125 String toString() { | 125 String toString() { |
126 if (errors.length == 1) return errors.single; | 126 if (errors.length == 1) return errors.single; |
127 return errors.map((e) => prefixLines(e, prefix: ' ', firstPrefix: '* ')) | 127 return errors.map((e) => prefixLines(e, prefix: ' ', firstPrefix: '* ')) |
128 .join('\n'); | 128 .join('\n'); |
129 } | 129 } |
130 } | 130 } |
OLD | NEW |