| 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:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 : super(name), | 24 : super(name), |
| 25 contents = contents.toList(); | 25 contents = contents.toList(); |
| 26 | 26 |
| 27 /// Creates a directory descriptor named [name] based on a directory on the | 27 /// Creates a directory descriptor named [name] based on a directory on the |
| 28 /// physical directory at [path]. | 28 /// physical directory at [path]. |
| 29 /// | 29 /// |
| 30 /// Note that reading from the filesystem isn't scheduled; it occurs as soon | 30 /// Note that reading from the filesystem isn't scheduled; it occurs as soon |
| 31 /// as this descriptor is constructed. | 31 /// as this descriptor is constructed. |
| 32 DirectoryDescriptor.fromFilesystem(String name, String path) | 32 DirectoryDescriptor.fromFilesystem(String name, String path) |
| 33 : this(name, new Directory(path).listSync().map((entity) { | 33 : this(name, new Directory(path).listSync().map((entity) { |
| 34 // Ignore hidden files. |
| 35 if (p.basename(entity.path).startsWith(".")) return null; |
| 36 |
| 34 if (entity is Directory) { | 37 if (entity is Directory) { |
| 35 return new DirectoryDescriptor.fromFilesystem( | 38 return new DirectoryDescriptor.fromFilesystem( |
| 36 p.basename(entity.path), entity.path); | 39 p.basename(entity.path), entity.path); |
| 37 } else if (entity is File) { | 40 } else if (entity is File) { |
| 38 return new FileDescriptor.binary( | 41 return new FileDescriptor.binary( |
| 39 p.basename(entity.path), entity.readAsBytesSync()); | 42 p.basename(entity.path), entity.readAsBytesSync()); |
| 40 } | 43 } |
| 41 // Ignore broken symlinks. | 44 // Ignore broken symlinks. |
| 42 })); | 45 }).where((path) => path != null)); |
| 43 | 46 |
| 44 Future create([String parent]) => schedule(() { | 47 Future create([String parent]) => schedule(() { |
| 45 if (parent == null) parent = defaultRoot; | 48 if (parent == null) parent = defaultRoot; |
| 46 var fullPath = p.join(parent, name); | 49 var fullPath = p.join(parent, name); |
| 47 return Chain.track(new Directory(fullPath).create(recursive: true)) | 50 return Chain.track(new Directory(fullPath).create(recursive: true)) |
| 48 .then((_) { | 51 .then((_) { |
| 49 return Future.wait( | 52 return Future.wait( |
| 50 contents.map((entry) => entry.create(fullPath)).toList()); | 53 contents.map((entry) => entry.create(fullPath)).toList()); |
| 51 }); | 54 }); |
| 52 }, 'creating directory:\n${describe()}'); | 55 }, 'creating directory:\n${describe()}'); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 146 |
| 144 _DirectoryValidationError(Iterable errors) | 147 _DirectoryValidationError(Iterable errors) |
| 145 : errors = errors.map((e) => e.toString()).toList(); | 148 : errors = errors.map((e) => e.toString()).toList(); |
| 146 | 149 |
| 147 String toString() { | 150 String toString() { |
| 148 if (errors.length == 1) return errors.single; | 151 if (errors.length == 1) return errors.single; |
| 149 return errors.map((e) => prefixLines(e, prefix: ' ', firstPrefix: '* ')) | 152 return errors.map((e) => prefixLines(e, prefix: ' ', firstPrefix: '* ')) |
| 150 .join('\n'); | 153 .join('\n'); |
| 151 } | 154 } |
| 152 } | 155 } |
| OLD | NEW |